Skip to content

Commit

Permalink
updated index docs
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed May 18, 2011
1 parent 9b86f21 commit d2a8ec5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/indexes.md
Expand Up @@ -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

Expand Down
18 changes: 16 additions & 2 deletions docs/insert.md
Expand Up @@ -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

Expand Down

0 comments on commit d2a8ec5

Please sign in to comment.