|
|
@ -323,9 +323,9 @@ db.count({}, function (err, count) { |
|
|
|
* `options` is an object with two possible parameters |
|
|
|
* `options` is an object with two possible parameters |
|
|
|
* `multi` (defaults to `false`) which allows the modification of several documents if set to true |
|
|
|
* `multi` (defaults to `false`) which allows the modification of several documents if set to true |
|
|
|
* `upsert` (defaults to `false`) if you want to insert a new document corresponding to the `update` rules if your `query` doesn't match anything |
|
|
|
* `upsert` (defaults to `false`) if you want to insert a new document corresponding to the `update` rules if your `query` doesn't match anything |
|
|
|
* `callback` (optional) signature: `err`, `numReplaced`, `upsert` |
|
|
|
* `callback` (optional) signature: `err`, `numReplaced`, `newDoc` |
|
|
|
* `numReplaced` is the number of documents replaced |
|
|
|
* `numReplaced` is the number of documents replaced |
|
|
|
* `upsert` is set to true if the upsert mode was chosen and a document was inserted |
|
|
|
* `newDoc` is the created document if the upsert mode was chosen and a document was inserted |
|
|
|
|
|
|
|
|
|
|
|
**Note**: you can't change a document's _id. |
|
|
|
**Note**: you can't change a document's _id. |
|
|
|
|
|
|
|
|
|
|
@ -373,7 +373,7 @@ db.update({ planet: 'Mars' }, { $unset: { planet: true } }, {}, function () { |
|
|
|
|
|
|
|
|
|
|
|
// Upserting a document |
|
|
|
// Upserting a document |
|
|
|
db.update({ planet: 'Pluton' }, { planet: 'Pluton', inhabited: false }, { upsert: true }, function (err, numReplaced, upsert) { |
|
|
|
db.update({ planet: 'Pluton' }, { planet: 'Pluton', inhabited: false }, { upsert: true }, function (err, numReplaced, upsert) { |
|
|
|
// numReplaced = 1, upsert = true |
|
|
|
// numReplaced = 1, upsert = { _id: 'id5', planet: 'Pluton', inhabited: false } |
|
|
|
// A new document { _id: 'id5', planet: 'Pluton', inhabited: false } has been added to the collection |
|
|
|
// A new document { _id: 'id5', planet: 'Pluton', inhabited: false } has been added to the collection |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|