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.
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.
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"] }});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With