Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongodb find by multiple array items

People also ask

How do I search multiple items in MongoDB?

MongoDB provides the find() that is used to find multiple values or documents from the collection. The find() method returns a cursor of the result set and prints all the documents. To find the multiple values, we can use the aggregation operations that are provided by MongoDB itself.

How do I query an array of objects in MongoDB?

To search the array of object in MongoDB, you can use $elemMatch operator. This operator allows us to search for more than one component from an array object.

How do I test multiple conditions in MongoDB?

Find Multiple Conditions Using the $or Operator The or operator in MongoDB is used to select or retrieve only documents that match at least one of the provided phrases. You can also use this operator in a method like a find() , update() , etc., as per the requirements.


Depends on whether you're trying to find documents where words contains both elements (text and here) using $all:

db.things.find({ words: { $all: ["text", "here"] }});

or either of them (text or here) using $in:

db.things.find({ words: { $in: ["text", "here"] }});