Reputation: 886
I have a MEAN stack application where I am using $http.post to add objects to a Mongo database that I am persisting in a local array. Is there a way of returning the generated ObjectID (._id) attribute when I post it?
I am trying to keep "pointers" in the local array so I can GET them later.
Upvotes: 0
Views: 246
Reputation: 2831
I don't know how MEAN stack mongo driver is working but in many cases, when you call insert by passing the javascript object, driver after successful insert modify the object with the new generated ObjectId or _v field. The generation of ObjectId in most cases is done by driver and not MongoDB server.
So in many cases returning the same object from post call does give you the ObjectId.
Maybe you can print the object after insert on the console to see if the driver is doing the work for you or not. If it's doing you can just return the same object as a response.
If it isn't doing so, bad luck.
Upvotes: 1