From 8ac65a7cbc2196819f5d7e9767acf487cf5daab0 Mon Sep 17 00:00:00 2001 From: Louis Chatriot Date: Mon, 24 Jun 2013 18:41:42 +0200 Subject: [PATCH] Update README.md --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4f44786..38de59e 100644 --- a/README.md +++ b/README.md @@ -138,13 +138,14 @@ db.findOne({ _id: 'id1' }, function (err, doc) { }); ``` -#### Comparison operators ($lt, $lte, $gt, $gte, $in, $nin, $ne) +#### Operators ($lt, $lte, $gt, $gte, $in, $nin, $ne, $exists) The syntax is `{ field: { $op: value } }` where `$op` is any comparison operator: * `$lt`, `$lte`: less than, less than or equal * `$gt`, `$gte`: greater than, greater than or equal * `$in`: member of. `value` must be an array of values * `$ne`, `$nin`: not equal, not a member of +* `$exists`: checks whether the document posses the property `field`. `value` should be true or false ```javascript // $lt, $lte, $gt and $gte work on numbers and strings @@ -161,6 +162,11 @@ db.find({ planet: { $gt: 'Mercury' }}, function (err, docs) { db.find({ planet: { $in: ['Earth', 'Jupiter'] }}, function (err, docs) { // docs contains Earth and Jupiter }); + +// Using $exists +db.find({ satellites: { $exists: true } }, function (err, docs) { + // docs contains only Mars +}); ``` #### Array fields