Permalink
Browse files

Fix a bug in collection.save.

  • Loading branch information...
1 parent 534c42e commit 45e357fa3f9d05d2d88d93466c8f7703e522adc7 @mbostock committed Jul 22, 2011
Showing with 7 additions and 2 deletions.
  1. +7 −2 lib/mongo-mock/collection.js
@@ -78,8 +78,13 @@ function collection(id, options) {
}
function save(object, options, callback) {
- if ("_id" in object) update({_id: object._id}, object, options, callback);
- else insert(object, options, callback);
+ if ("_id" in object) {
+ if (options) options.upsert = true;
+ else options = {upsert: true};
+ update({_id: object._id}, object, options, callback);
+ } else {
+ insert(object, options, callback);
+ }
}
function remove(query, options, callback) {

0 comments on commit 45e357f

Please sign in to comment.