$in¶
-
$in¶ Syntax:
{ field: { $in: [<value1>, <value2>, ... <valueN> ] } }$inselects the documents where thefieldvalue equals any value in the specified array (e.g.<value1>,<value2>, etc.)Consider the following example:
This query selects all documents in the
inventorycollection where theqtyfield value is either5or15. Although you can express this query using the$oroperator, choose the$inoperator rather than the$oroperator when performing equality checks on the same field.If the
fieldholds an array, then the$inoperator selects the documents whosefieldholds an array that contains at least one element that matches a value in the specified array (e.g.<value1>,<value2>, etc.)Consider the following example:
This
update()operation will set thesalefield value in theinventorycollection where thetagsfield holds an array with at least one element matching an element in the array["appliances", "school"].