O
O
Oleg-Ukraine2018-08-22 18:20:29
MongoDB
Oleg-Ukraine, 2018-08-22 18:20:29

How to search in an array of a document?

Hello everyone, I would be grateful for help with building a query
there is a document

{ "_id" : 1, "name" : "dave123", "status" : "active", favorites: [ "chocolate", "cake", "butter", "apples" ],  ingredients: [ "chocolate", "cake", "butter", "ice cream" ] }
{ "_id" : 2, "name" : "li", "status" : "notActive" , favorites: [ "apples", "pudding", "pie" ] ,  ingredients: [ "chocolate", "cake", "ice cream", "apples" ] }
{ "_id" : 3, "name" : "ahn", "status" : "active", favorites: [ "pears", "pecans", "chocolate", "cherries" ],  ingredients: [ "chocolate", "cake", "butter", "apples" ]  }
{ "_id" : 4, "name" : "ty", "status" : "notActive", favorites: [ "chocolate", "ice cream" ] ,  ingredients: [ "chocolate", "cake", "butter", "apples" ] }

How to filter documents in monge and get only those with status = active, where favorites has chocolate, and ingredients has ["cake", "butter"] array. I would be very grateful for help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lega, 2018-08-22
@lega

see filters $eq, $in, $all

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question