Skip to content
Advertisement

Tag: mongoose

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

Mongoose Return Error Code 11000 duplicate index

i am using mongoose as database for my project, now i am struggling with add data to multiple collections and this is my route router.post(‘/’,add_new_user_to_specific_collection,add_new_user_to_collection_User); this is code of middleware add_new_user_to_specific_collection: and this is for add_new_user_to_collection_User: the input data is totally validated, and at the first try, it worked perfectly, but when it comes to the second times, i got

TypeError: Order.find is not a function

I am building ecommerce website using MERN stack. And I am getting error while testing using Postman. backend/controllers/user.js backend/models/Order.js backend/models/User.js backend/routes/user.js Error:- TypeError: Order.find is not a function at exports.userPurchaseList (C:UsersRahulMernBootcampprojbackendcontrollersuser.js:47:9) TESTING this route using POSTMAN. Answer You have exported an object so in your backend/controllers/user.js you could import it like so from destructuring from the object then the rest

Mongoose populate subdocument in array

I have a Mongoose offer model explained below: and order schema which has reference to to the first schema offer explained below: the problem that I can not populate sections here {section: { type: Schema.Types.ObjectId, ref: ‘Offer.sections’ }} it gives me MissingSchemaError: Schema hasn’t been registered for model “Offer.sections”. so is there any way to populate sections? Answer Unfortunately, Mongoose

Advertisement