Mongodb/Mongoose in Node.js. Finding by id of the nested document
For some reason I can't find a document when I search by the id of a nested document. I can perform other finds easily enough so these two work:
User.findOne({"_id" : some_id}, function(err,user){}
User.findOne({"arrayOfNestedDocs.value":someValue}, function(err,user){}
But finding by id of nested doc doesn't work:
User.findOne({"arrayOfN开发者_开发技巧estedDocs._id" : some_id}, function(err,user){}
I can perform the search in a mongo shell so but not via mongoose. Any ideas would be helpful.
I've added it as an issue in the project
If you're trying to find an embedded document then the syntax is:
User.findOne({_id: id}, function(err, user) {
var embeddedDoc = user.embeddedDocs.id('embeddedDocId');
});
精彩评论