Greetings all,
Apologies if this is a double post, I could have sworn I posted this two days ago, but it seems to have disappeared.
I'd like to get the ObjectID of the document I've just save()'ed. It seems like this should be obvious, but I'm missing it. Here's what I'm doing at the moment:
var Obj = db.model('Object');
app.post('/object', function(req, res) {
doc = new Obj({ blah, blah });
doc.save(function(err) {
...
res.redirect('/object/' + doc._id); <-- Hmmm, I don't actually have the _id... =(
});
});
I've tried using a 'standard' callback on the save method with a signature like:
var Obj = db.model('Object');
app.post('/object', function(req, res) {
tmp = new Obj({ blah, blah });
tmp.save(function(err, obj) {
...
res.redirect('/object/' + doc._id); <-- Hmmm, I don't actually have the _id... =(
});
});
but it doesn't seem to work. What am I missing?
I'm using: Node v0.4.0, Mongoose v1.0.16, MongoDB v1.6.6-pre