У меня есть модель схемы, как:находка идентификатор последней поддокументе вставляется в мангуста
var A = new Schema ({
a: String,
b : [ { ba: Integer, bb: String } ]
}, { collection: 'a' });
затем
var M = mongoose.model("a", A);
var saveid = null;
var m = new M({a:"Hello"});
m.save(function(err,model){
saveid = model.id;
}); // say m get the id as "1"
затем
m['b'].push({ba:235,bb:"World"});
m.save(function(err,model){
console.log(model.id); //this will print 1, that is the id of the main Document only.
//here i want to find the id of the subdocument i have just created by push
});
Так что мой вопрос, как найти идентификатор из поддокумента, просто вдвинутого в одно поле модели.
это действительно единственный способ? – kumikoda
Проблемы с синхронизацией с асинхронными вызовами базы данных могут сделать это плохой идеей. – bbengfort