From 8b552759431edac1a4793d0fbf389fec1c51edda Mon Sep 17 00:00:00 2001 From: Louis Chatriot Date: Fri, 2 Aug 2013 12:35:13 +0200 Subject: [PATCH] Update README.md --- README.md | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 37461c4..7688dbf 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ It's a subset of MongoDB's API (the most used operations). The current API will * Creating/loading a database * Inserting documents * Finding documents +* Counting documents * Updating documents * Removing documents * Indexing @@ -164,19 +165,6 @@ db.findOne({ _id: 'id1' }, function (err, doc) { }); ``` -#### Counting objects -Similar to `find`, you can count the number of matching documents by calling `count`. For example - -```javascript -// Using same datastore as above - -// Count all planets in the solar system -db.count({ system: 'solar' }, function (err, count) { - // count equals to 3 - // If no document is found, count is 0 -}); -``` - #### Operators ($lt, $lte, $gt, $gte, $in, $nin, $ne, $exists, $regex) The syntax is `{ field: { $op: value } }` where `$op` is any comparison operator: @@ -256,6 +244,21 @@ db.find({ $or: [{ planet: 'Earth' }, { planet: 'Mars' }], inhabited: true }, fun ``` +### Counting documents +With the same syntax as `find`, you can count the number of matching documents by using `count`. For example: + +```javascript +// Count all planets in the solar system +db.count({ system: 'solar' }, function (err, count) { + // count equals to 3 +}); + +// Count all documents in the datastore +db.count({}, function (err, count) { + // count equals to 4 +}); +``` + ### Updating documents `db.update(query, update, options, callback)` will update all documents matching `query` according to the `update` rules: * `query` is the same kind of finding query you use with `find` and `findOne`