|
8 | 8 |
|
9 | 9 | *Syntax*: ``{ field: { $in: [<value1>, <value2>, ... <valueN> ] } }`` |
10 | 10 |
|
11 | | - :operator:`$in` selects the documents where the ``field`` equals any |
12 | | - value in the specified array (e.g. ``<value1>``, <value2>``, etc.) |
| 11 | + :operator:`$in` selects the documents where the ``field`` value |
| 12 | + equals any value in the specified array (e.g. ``<value1>``, |
| 13 | + ``<value2>``, etc.) |
| 14 | + |
13 | 15 | Consider the following example: |
14 | 16 |
|
15 | 17 | .. code-block:: javascript |
16 | 18 |
|
17 | 19 | db.inventory.find( { qty: { $in: [ 5, 15 ] } } ) |
18 | 20 |
|
19 | | - This query will select to select all documents in ``inventory`` |
20 | | - where ``qty`` is either ``5`` or ``15``. Although you can express |
21 | | - this query using the :operator:`$or` operator, prefer |
22 | | - :operator:`$in` in favor of :operator:`$or` when performing |
23 | | - equality checks on a single field. |
| 21 | + This query will select to select all documents in the ``inventory`` |
| 22 | + collection where the ``qty`` field value is either ``5`` or |
| 23 | + ``15``. Although you can express this query using the |
| 24 | + :operator:`$or` operator, choose the :operator:`$in` operator rather |
| 25 | + than the :operator:`$or` operator when performing equality checks on |
| 26 | + the same field. |
24 | 27 |
|
25 | | - If the field holds an array, then the following expression is true |
26 | | - *if* any element specified with the :operator:`$in` expression is |
27 | | - in the array. |
28 | | - |
29 | | - .. code-block:: javascript |
| 28 | + If the ``field`` holds an array, then the :operator:`$in` operator |
| 29 | + selects the documents whose ``field`` holds an array that contains |
| 30 | + at least one element that matches a value in the specified array |
| 31 | + (e.g. ``<value1>``, ``<value2>``, etc.) |
30 | 32 |
|
31 | | - { field: { $in: [ array ] } } |
32 | | - |
33 | 33 | Consider the following example: |
34 | 34 |
|
35 | 35 | .. code-block:: javascript |
36 | 36 |
|
37 | 37 | db.inventory.update( { tags: { $in: ["appliances", "school"] } }, { $set: { sale:true } } ) |
38 | 38 |
|
39 | 39 | This :method:`update() <db.collection.update()>` operation will set |
40 | | - the value of ``sale`` in the ``inventory`` collection where at |
41 | | - least one element of the ``tags`` array matches an element in the |
42 | | - array ``["appliances", "school"]``. |
| 40 | + the ``sale`` field value in the ``inventory`` collection where the |
| 41 | + ``tags`` field holds an array with at least one element matching an |
| 42 | + element in the array ``["appliances", "school"]``. |
43 | 43 |
|
44 | 44 | .. seealso:: |
45 | 45 |
|
|
0 commit comments