Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.....

like image 882
Yashwanth K Avatar asked Feb 02 '26 11:02

Yashwanth K


1 Answers

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.

like image 86
Yashwanth K Avatar answered Feb 05 '26 04:02

Yashwanth K