Matching values in an array using $in operator
In this example, we are retrieving only those employee’s documents who is working with either C#, Python, or both languages.
db.contributor.find({language: {$ in : [ "C#" , "Python" ]}}).pretty() |
MongoDB $in Operator
MongoDB provides different types of comparison query operators and $in operator is one of them. This operator is used to select those documents where the value of the field is equal to any of the given value in the array. And if the field contains an array, then this operator selects only those documents whose field contains an array that holds at least one item that matches a value of the specified array. You can use this operator in methods like find(), update(), etc. according to your requirements.
Syntax:
{field: {$in: [value1, value2, value3, ...]}}
In the following examples, we are working with:
Database: w3wiki
Collection: contributor
Document: three documents that contain the details of the contributors in the form of field-value pairs.
Contact Us