File tree Expand file tree Collapse file tree 2 files changed +11
-9
lines changed
source/reference/operator Expand file tree Collapse file tree 2 files changed +11
-9
lines changed Original file line number Diff line number Diff line change 39
39
40
40
db.inventory.find( { price: 1.99, qty: { $lt: 20 } , sale: true } )
41
41
42
- If, however, a query requires an ``AND`` operation on the same
43
- field, you *must* use the :operator:`$and` operator as in the
44
- following example:
42
+ If, however, a query requires an ``AND`` operation on the same field
43
+ such as ``{ $price: { $ne: 1.99 } } AND { price: { $exists: true }
44
+ }``, then either use the :operator:`$and` operator for the two
45
+ separate expressions or combine the operator expressions for the
46
+ field ``{ $price: { $ne: 1.99, $exists: true } }``.
45
47
48
+ Consider the following examples:
49
+
46
50
.. code-block:: javascript
47
51
48
52
db.inventory.update( { $and: [ { price: { $ne: 1.99 } }, { price: { $exists: true } } ] }, { $set: { qty: 15 } } )
49
53
50
- This :method:`update() <db.collection.update()>` operation will set
54
+ db.inventory.update( { price: { $ne: 1.99, $exists: true } } , { $set: { qty: 15 } } )
55
+
56
+ Both :method:`update() <db.collection.update()>` operations will set
51
57
the value of the ``qty`` field in documents where:
52
58
53
59
- the ``price`` field value does not equal ``1.99`` **and**
Original file line number Diff line number Diff line change @@ -17,15 +17,11 @@ $exists
17
17
18
18
.. code-block:: javascript
19
19
20
- db.inventory.find( { $and: [ { qty: { $exists: true } }, { qty: { $nin: [ 5, 15 ] } } ] } )
20
+ db.inventory.find( { qty: { $exists: true, $nin: [ 5, 15 ] } } )
21
21
22
22
This query will select all documents in the ``inventory`` collection
23
23
where the ``qty`` field exists *and* its value does not equal either
24
24
``5`` nor ``15``.
25
-
26
- The above query used the :operator:`$and` operator because the query
27
- performs an ``AND`` operation on the value of the same field and is
28
- not specific to the :operator:`$exists` operator.
29
25
30
26
.. seealso::
31
27
You can’t perform that action at this time.
0 commit comments