Ticket: Migration MongoParseError

Hi,

I am getting this error while trying to run my code:

Error during migration, MongoParseError: URI malformed, cannot be parsed

Please find the code:

const predicate = { lastupdated :{ $exists :true , $type : “string”} }
//const predicate = { $or: [ { lastupdated :{ $exists:false } }, { $type: “string” } ]}
const projection = { lastupdated: 1 }
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)) },
},
},
}))
console.log(
“\x1b[32m”,
Found ${moviesToMigrate.length} documents to update,
)
// TODO: Complete the BulkWrite statement below
const { modifiedCount } = await mflix.collection(“movies”).bulkWrite(
moviesToMigrate,(err, r) =>{
assert.equal(null, err);
})

Hi @Ankur_Pandey :wave: ,
Can you please take a look at the following discussions?

If you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
MongoDB

1 Like

Hi @SourabhBagrecha ,

I looked into the discussions. I am using the same MongoURI string as suggested. But I am still facing the same issue. Am I getting this erro due to my code?

Hi @Ankur_Pandey, thanks for confirming.
Since the error states URI malformed I am not sure if it can be fixed through the code. Can you please try the suggestions mentioned here?

If you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
MongoDB

1 Like

Thanks @SourabhBagrecha ,

As I went through the comments, I found
require("dotenv").config({ path: '../../.env' })
to be modified. So I have solved that problem. But now I am getting

Error during migration, TypeError: Cannot destructure property ‘modifiedCount’ of ‘(intermediate value)’ as it is undefined.

Is there something wrong with my code.
Also I wanted some help on Ticket: Resiliency - M220JS: MongoDB for Javascript Developers - MongoDB Developer Community Forums

Thanks and Regards,
Ankur

and

These were the errors.

Thanks, @SourabhBagrecha , for the help.

Thanks and regards,
Ankur Pandey

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.