Answer the question
In order to leave comments, you need to log in
How to get an element by ID(objectId) if it is inside another model?
Good afternoon, there is a Restaurant model where there is an array of products that has its own ObjectID. The question is how to do a search exactly by that ObjectID in order to get its fields (price, names, etc.)
I tried all the methods but it doesn’t work, and I have a feeling that it won’t be possible to get exactly the object if it is nested
. For example, properties
Restaurant.find({products: {$elemMatch: {"_id": product_id}}})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question