Mongodb / Mongoose in Node.js. Search by ID of the attached document

For some reason, I cannot find the document when searching by the ID of the attached document. I can perform other finds quite easily, so these two work:

User.findOne({"_id" : some_id}, function(err,user){} User.findOne({"arrayOfNestedDocs.value":someValue}, function(err,user){} 

But searching by id of the attached document does not work:

 User.findOne({"arrayOfNestedDocs._id" : some_id}, function(err,user){} 

I can do a search in the mongo shell, but not through mongoose. Any ideas would be helpful.

+4
source share
2 answers

I added it as a problem to the project

+1
source

If you are trying to find an embedded document, the syntax is as follows:

 User.findOne({_id: id}, function(err, user) { var embeddedDoc = user.embeddedDocs.id('embeddedDocId'); }); 
0
source

All Articles