Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Find and return data that contains mongoose ID and name

I have following Collections:

[{
name: "apple",
class: [620e112a03914a837dcd7585,620e112a03914a837dcd4325]
},
{
name: "orange",
class: [620e112a03914a837dcd4325,620e112a03914a837dcd7712]
}]

I want to execute the query like

Find all the documents which have name 'apple' and have class '620e112a03914a837dcd4325'

How are we suppose to do this in mongoose/mongodB??

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Assuming your model is called Product, you could do it like this:

Product.find({name: 'apple', class: {"$in": ['620e112a03914a837dcd4325']}})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading