I want to retrieve the last inserted
_id, using mongoose as MongoDB wrapper for node.js. I've found the following tutorial, but I can't change any node modules because the app runs on a public server:
Any other ideas? This what I want to do:
I'm using mongoose version 1.2.0 and as soon as I created a new instance of a mongoose model, the
_id is already set.
coffee> u = new User() [object Object] coffee> u._id 4dd68fc449aaedd177000001
I also verified that after I call
_id remains the same. I verified via MongoHub that this is indeed the real ID saved into MongoDB.
If you explicitly declare
for your model, then the ObjectId will not be available after new or save. This is probably a bug.