Skip to content

Changed misleading parameter name #1427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 8, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ define.classMethod('updateOne', {callback: true, promise:true});
* @param {Collection~updateWriteOpCallback} [callback] The command result callback
* @return {Promise} returns Promise if no callback passed
*/
Collection.prototype.replaceOne = function(filter, update, options, callback) {
Collection.prototype.replaceOne = function(filter, doc, options, callback) {
var self = this;
if(typeof options == 'function') callback = options, options = {};
options = shallowClone(options)
Expand All @@ -928,30 +928,30 @@ Collection.prototype.replaceOne = function(filter, update, options, callback) {
}

// Execute using callback
if(typeof callback == 'function') return replaceOne(self, filter, update, options, callback);
if(typeof callback == 'function') return replaceOne(self, filter, doc, options, callback);

// Return a Promise
return new this.s.promiseLibrary(function(resolve, reject) {
replaceOne(self, filter, update, options, function(err, r) {
replaceOne(self, filter, doc, options, function(err, r) {
if(err) return reject(err);
resolve(r);
});
});
}

var replaceOne = function(self, filter, update, options, callback) {
var replaceOne = function(self, filter, doc, options, callback) {
// Set single document update
options.multi = false;
// Execute update
updateDocuments(self, filter, update, options, function(err, r) {
updateDocuments(self, filter, doc, options, function(err, r) {
if(callback == null) return;
if(err && callback) return callback(err);
if(r == null) return callback(null, {result: {ok:1}});
r.matchedCount = r.result.n;
r.modifiedCount = r.result.nModified != null ? r.result.nModified : r.result.n;
r.upsertedId = Array.isArray(r.result.upserted) && r.result.upserted.length > 0 ? r.result.upserted[0] : null;
r.upsertedCount = Array.isArray(r.result.upserted) && r.result.upserted.length ? r.result.upserted.length : 0;
r.ops = [update];
r.ops = [doc];
if(callback) callback(null, r);
});
}
Expand Down