Updated readme

pull/2/head
Louis Chatriot 11 years ago
parent fb640b308e
commit 33f7f18a23
  1. 14
      README.md
  2. 3
      test/db.test.js

@ -113,6 +113,20 @@ db.insert(document, function (err, newDoc) { // Callback is optional
}); });
``` ```
You can also bulk-insert an array of documents. This operation is atomic, meaning that if one insert fails due to a unique constraint being violated, all changes are rolled back.
```javascript
db.insert([{ a: 5 }, { a: 42 }], function (err, newDocs) {
// Two documents were inserted in the database
// newDocs is an array with these documents, augmented with their _id
});
// If there is a unique constraint on field 'a', this will fail
db.insert([{ a: 5 }, { a: 42 }, { a: 5 }], function (err) {
// err is a 'uniqueViolated' error
// The database was not modified
});
```
### Finding documents ### Finding documents
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.

@ -210,8 +210,7 @@ describe('Database', function () {
d.ensureIndex({ fieldName: 'a', unique: true }); d.ensureIndex({ fieldName: 'a', unique: true });
d.insert(docs, function (err) { d.insert(docs, function (err) {
assert.isDefined(err); err.errorType.should.equal('uniqueViolated');
assert.isNotNull(err);
d.find({}, function (err, docs) { d.find({}, function (err, docs) {
docs.length.should.equal(0); docs.length.should.equal(0);

Loading…
Cancel
Save