diff --git a/docs/indexes.md b/docs/indexes.md index 0120c4ff2d..ebe20e5c94 100644 --- a/docs/indexes.md +++ b/docs/indexes.md @@ -65,7 +65,7 @@ All indexes can be dropped at once with `dropIndexes` Where `callback` gets two parameters - an error object (if an error occured) and an index information object. -The keys in the index object are the index names and the values are tuples of ioncluded fields. +The keys in the index object are the index names and the values are tuples of included fields. For example if a collection has two indexes - as a default an ascending index for the `_id` field and an additonal descending index for `"username"` field, then the index information object would look like the following diff --git a/docs/insert.md b/docs/insert.md index 843b2f5fed..a05bf65cce 100644 --- a/docs/insert.md +++ b/docs/insert.md @@ -26,8 +26,22 @@ For example console.log("Record added as "+records[0]._id); }); -Simple update can be done as a regular insert but with the `_id` value set - if a record with this id value exists, -it will be overwritten. +If trying to insert a record with an existing `_id` value, then the operation yields in error. + + collection.insert({_id:1}, {safe:true}, function(err, doc){ + // no error, inserted new document, with _id=1 + collection.insert({_id:1}, {safe:true}, function(err, doc){ + // error occured since _id=1 already existed + }); + }); + +## Save + +Shorthand for insert/update is `save` - if `_id` value set, the record is updated if it exists or inserted if it does not; if the `_id` value is not set, then the record is inserted as a new one. + + collection.save({_id:"abc", user:"David"},{safe:true}, callback) + +`callback` gets two parameters - an error object (if an error occured) and the record if it was inserted or `1` if the record was updated. ## Update