Answer the question
In order to leave comments, you need to log in
Where can an ObjectID be lost and replaced with a string?
The back-end part, having made a selection from Mongoose, sends it using Express (res.send) to the front-end JSON (Array of objects. Each object has an _id, which is assigned automatically). After objects are retrieved one by one from the array on the front-end and subjected to changes, they are returned one by one to the back-end via http (POST request, type: application/JSON ) in Angular. When the back-end receives (via express) modified objects and tries to update them, the _id that came from the front-end and is retrieved via req.body._id does not match the ObjectId format - Mongo gives an error that this is not an ObjectId type. It may have become a string. I tried to use the ObjectId(req.body._id) function, but it gives an error: "hex not a function".
But if you do the same operations, but without passing them to the front-end, then _id retains its type (ObjectId) and is normally fed into the database.
Where can ObjectID be lost and replaced with a string?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question