Skip to content

Tag: mongodb

Export data from MongoDB with MongoExport and query

I’m trying to get a data which doesn’t start with “0”. This query works inside of MongoDB command line but when I do this with mongoexport as I’m getting an error And with like this {“number”: “/^(?!0)/”} it wont match… How could I parse that /^(?!0)…

MongoDb update with ElemMatch

I have a collection that has document structure like following: Mongo PlayGround As you can see, each document has basicDetails object and a tasks array. Each task contains some properties of its own and a subtasks array. I want to update subtasks’s description from ABC to XYZ where root level id is 1, …

ReferenceError: require is not defined MongoDB

I’m trying to connect to my MongoDB database and I’m getting this error Answer You are attempting to use require() inside an ESM module (you can see the Object.loadESM in the call stack of the error) which tells us it’s an ESM module. You can’t use require() in that type of module. Ins…

How to handle for Cast Errors in MongoDB/mongoose

I am using mongoDB. I don’t like the default error message that is thrown by mongoose/mongoDB. I would like to check for the error type and if it is a cast error then I would like to send a different error message. Answer here is my function to do that. this function take an error and if it was a