Query Object list

Jithin shared this question 6 years ago
Answered

I have a collection named 'vendors' and there is a field called 'products' in that collection.The products field is a collection of object.Each object contains a 'productno' and 'productname' field. How can I get a products with a specific 'productno'?

Replies (1)

photo
1

I seems that you need $elemMatch.

db.vendors.find({
   products: { $elemMatch: { productno: 123, productname: "abc" }} 

})
or user our fluid query:
db.vendors.where("products").elemMatch({productno:123, productname:"abc"})

Leave a Comment
 
Attach a file