Hello, I wrote this code. It worked fine, but when I ran it twice, Mongodb lost some dates as “Invalid Dates”. So the test is not working. I don’t know how can I restore the entire documents collection from scratch.
const predicate = { lastupdated: { $exists: true } }
const projection = {}
const cursor = await mflix
.collection(“movies”)
.find(predicate, projection)
.toArray()
const moviesToMigrate = cursor.map(({ _id, lastupdated }) => ({
updateOne: {
filter: { _id: ObjectId(_id) },
update: {
$set: { lastupdated: new Date(Date.parse(lastupdated)).toISOString() },
$convert: {input: lastupdated, to: 'date'},
},
},
}))