diff --git a/source/reference/operator/and.txt b/source/reference/operator/and.txt index 139ad20f46a..dbabf7f563d 100644 --- a/source/reference/operator/and.txt +++ b/source/reference/operator/and.txt @@ -39,15 +39,21 @@ $and db.inventory.find( { price: 1.99, qty: { $lt: 20 } , sale: true } ) - If, however, a query requires an ``AND`` operation on the same - field, you *must* use the :operator:`$and` operator as in the - following example: + If, however, a query requires an ``AND`` operation on the same field + such as ``{ $price: { $ne: 1.99 } } AND { price: { $exists: true } + }``, then either use the :operator:`$and` operator for the two + separate expressions or combine the operator expressions for the + field ``{ $price: { $ne: 1.99, $exists: true } }``. + Consider the following examples: + .. code-block:: javascript db.inventory.update( { $and: [ { price: { $ne: 1.99 } }, { price: { $exists: true } } ] }, { $set: { qty: 15 } } ) - This :method:`update() ` operation will set + db.inventory.update( { price: { $ne: 1.99, $exists: true } } , { $set: { qty: 15 } } ) + + Both :method:`update() ` operations will set the value of the ``qty`` field in documents where: - the ``price`` field value does not equal ``1.99`` **and** diff --git a/source/reference/operator/exists.txt b/source/reference/operator/exists.txt index a0527c88009..574bd707514 100644 --- a/source/reference/operator/exists.txt +++ b/source/reference/operator/exists.txt @@ -17,15 +17,11 @@ $exists .. code-block:: javascript - db.inventory.find( { $and: [ { qty: { $exists: true } }, { qty: { $nin: [ 5, 15 ] } } ] } ) + db.inventory.find( { qty: { $exists: true, $nin: [ 5, 15 ] } } ) This query will select all documents in the ``inventory`` collection where the ``qty`` field exists *and* its value does not equal either ``5`` nor ``15``. - - The above query used the :operator:`$and` operator because the query - performs an ``AND`` operation on the value of the same field and is - not specific to the :operator:`$exists` operator. .. seealso::