node.jsmongooseobjectid

Class constructor ObjectId cannot be invoked without 'new' in mongoose


When I send data from frontend to backend via API request I got this error:

Class constructor ObjectId can not be invoked without 'new' in mongoose,

I tried to convert into string and also into int but it didn't work.....


Solution

  • I am new to nodejs too, i am trying to post some questions, even answers that i am not able to find.

    Here the problem not from frontend and backend, it is from mongoose schema

    when we are converting data to objectId we just need to declare new

    .

    Solution: new mongoose.Types.ObjectId(Id)

    If you find helpful then like the answer so others reach fast.