Reputation: 4004
I want to get the id of a created document without having to make a separate query to get the document after it is created. I'm thinking I'll need to manually create the id of the document before creating it. Is there a way to do this? I'm using the mongoose
driver.
Upvotes: 0
Views: 666
Reputation: 311835
Once you create a new mongoose model instance, its _id
value is already set to what it will be when saved. For example:
var user = new User();
// user._id is already set.
...
user.save();
Upvotes: 1