From 8e6670459b8c3239be628a103f17c1c3551f4bad Mon Sep 17 00:00:00 2001 From: Louis Chatriot Date: Thu, 23 May 2013 19:40:04 +0200 Subject: [PATCH] Update README.md --- README.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9fc7c3a..a595adf 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ db.insert(document, function (err, newDoc) { // Callback is optional ``` ### Finding documents -You can use `find` to look for multiple documents matching you query, or `findOne` to look for one specific document. You can select documents based on field equality or use comparison operators (`$lt`, `$lte`, `$gt`, `$gte`, `$in`, `$nin`, `$ne`). You can also use logical operators `$or`, `$and` and `$not`. See below for the syntax. +Use `find` to look for multiple documents matching you query, or `findOne` to look for one specific document. You can select documents based on field equality or use comparison operators (`$lt`, `$lte`, `$gt`, `$gte`, `$in`, `$nin`, `$ne`). You can also use logical operators `$or`, `$and` and `$not`. See below for the syntax. #### Basic querying @@ -154,17 +154,21 @@ db.find({ satellites: { $in: ['Moon', 'Deimos'] } }, function (err, docs) { }); ``` -#### Logical operators +#### Logical operators $or, $and, $not +You can combine queries using logical operators: +* For `$or` and `$and`, the syntax is `{ $op: [query1, query2, ...] }`. +* For `$not`, the syntax is `{ $not: query }` ```javascript -// You can use logical operator $or and $and ($and is the same -// as just using a normal query object) -// Syntax is { $logicalOperator: [query1, query2, ...] } db.find({ $or: [{ planet: 'Earth' }, { planet: 'Mars' }] }, function (err, docs) { // docs contains Earth and Mars }); +db.find({ $not: { planet: 'Earth' } }, function (err, docs) { + // docs contains Mars, Jupiter, Omicron Persei 8 +}); + // You can mix normal queries, comparison queries and logical operators db.find({ $or: [{ planet: 'Earth' }, { planet: 'Mars' }], inhabited: true }, function (err, docs) { // docs contains Earth