Permalink
Browse files

updated index docs

  • Loading branch information...
1 parent 9b86f21 commit d2a8ec537bc61ac8ea6712bb0565e69dae298622 andris9 committed May 18, 2011
Showing with 17 additions and 3 deletions.
  1. +1 −1 docs/indexes.md
  2. +16 −2 docs/insert.md
View
@@ -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
View
@@ -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

0 comments on commit d2a8ec5

Please sign in to comment.