Skip to content

Commit

Permalink
returning update document at the end of the callback for update docs,…
Browse files Browse the repository at this point in the history
… (Issue #569)
  • Loading branch information
christkv committed Mar 30, 2012
1 parent 4bd8c72 commit 157ed4c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions HISTORY
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Corrupt GridFS files when chunkSize < fileSize, fixed concurrency issue (Issue #555)
- Handle dead tailable cursors (Issue #568, https://github.com/aheckmann)
- Connection pools handles closing themselves down and clearing the state
- Check bson size of documents against maxBsonSize and throw client error instead of server error, (Issue #553)

0.9.9.7 2012-03-16
------------------
Expand Down
5 changes: 3 additions & 2 deletions lib/mongodb/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,14 @@ Collection.prototype.update = function update(selector, document, options, callb
this.db._executeUpdateCommand(updateCommand, commandOptions, function (err, error) {
error = error && error.documents;
if(!callback) return;

if(err) {
callback(err);
} else if(error[0].err || error[0].errmsg) {
callback(self.db.wrap(error[0]));
} else {
callback(null, error[0].n);
// Perform the callback
callback(null, error[0].n, error[0]);
}
});
} else {
Expand Down
23 changes: 23 additions & 0 deletions test/insert_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,29 @@ exports.shouldFailDueToInsertBeingBiggerThanMaxDocumentSizeAllowed = function(te
});
}

/**
* @ignore
*/
exports.shouldCorrectlyPerformUpsertAgainstNewDocumentAndExistingOne = function(test) {
client.createCollection('shouldCorrectlyPerformUpsertAgainstNewDocumentAndExistingOne', function(err, collection) {
// Upsert a new doc
collection.update({a:1}, {a:1}, {upsert:true, safe:true}, function(err, result, status) {
test.equal(1, result);
test.equal(false, status.updatedExisting);
test.equal(1, status.n);
test.ok(status.upserted != null);

// Upsert an existing doc
collection.update({a:1}, {a:1}, {upsert:true, safe:true}, function(err, result, status) {
test.equal(1, result);
test.equal(true, status.updatedExisting);
test.equal(1, status.n);
test.done();
});
});
});
}

/**
* Retrieve the server information for the current
* instance of the db client
Expand Down

4 comments on commit 157ed4c

@aheckmann
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woot! why not just pass the result doc directly and remove the number affected param? If not now probably something we should do in the 1.0 release.

@christkv
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will break everyone so probably not

@aheckmann
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.0.0 is a good time to make api changes. this is your chance to fix any api "problems" from the past two years

@christkv
Copy link
Contributor Author

@christkv christkv commented on 157ed4c Mar 31, 2012 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.