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:
Getting “Last Inserted ID” (hint – you have to hack Mongoose)
Any other ideas? This what I want to do:
- Insert new user
- Get user’s
_idvalue - Set a new session based on user’s id
- Redirect to /
Thanks!
I’m using mongoose version 1.2.0 and as soon as I created a new instance of a mongoose model, the
_idis already set.I also verified that after I call
u.save()the_idremains the same. I verified via MongoHub that this is indeed the real ID saved into MongoDB.