From f5ee9fe652836c3220266233d32c01ea478561fd Mon Sep 17 00:00:00 2001 From: Katherine Walker Date: Mon, 30 Jul 2018 17:57:27 -0400 Subject: [PATCH 1/4] fix(db_ops): call collection.find() with correct parameters Fixes NODE-1596 --- lib/operations/db_ops.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/operations/db_ops.js b/lib/operations/db_ops.js index 9e35f7d344..10f48a2337 100644 --- a/lib/operations/db_ops.js +++ b/lib/operations/db_ops.js @@ -15,7 +15,7 @@ const toError = require('../utils').toError; const count = require('./collection_ops').count; const findOne = require('./collection_ops').findOne; const remove = require('./collection_ops').remove; -const update = require('./collection_ops').update; +const updateOne = require('./collection_ops').updateOne; const debugFields = [ 'authSource', @@ -90,8 +90,9 @@ function addUser(db, username, password, options, callback) { // We got an error (f.ex not authorized) if (err != null) return handleCallback(callback, err, null); // Check if the user exists and update i + finalOptions.projection = { dbName: 1 }; collection - .find({ user: username }, { dbName: options['dbName'] }, finalOptions) + .find({ user: username }, finalOptions) .toArray(err => { // We got an error (f.ex not authorized) if (err != null) return handleCallback(callback, err, null); @@ -99,7 +100,7 @@ function addUser(db, username, password, options, callback) { finalOptions.upsert = true; // We have a user, let's update the password or upsert if not - update( + updateOne( collection, { user: username }, { $set: { user: username, pwd: userPassword } }, @@ -592,7 +593,7 @@ function profilingInfo(db, options, callback) { try { db .collection('system.profile') - .find({}, null, options) + .find({}, options) .toArray(callback); } catch (err) { return callback(err, null); From 99cbbb0eb47d2c3a66a6d61fa38922ee2713a8de Mon Sep 17 00:00:00 2001 From: Katherine Walker Date: Mon, 30 Jul 2018 18:04:39 -0400 Subject: [PATCH 2/4] fix format --- lib/operations/db_ops.js | 42 +++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/lib/operations/db_ops.js b/lib/operations/db_ops.js index 10f48a2337..4b8a122a67 100644 --- a/lib/operations/db_ops.js +++ b/lib/operations/db_ops.js @@ -91,28 +91,26 @@ function addUser(db, username, password, options, callback) { if (err != null) return handleCallback(callback, err, null); // Check if the user exists and update i finalOptions.projection = { dbName: 1 }; - collection - .find({ user: username }, finalOptions) - .toArray(err => { - // We got an error (f.ex not authorized) - if (err != null) return handleCallback(callback, err, null); - // Add command keys - finalOptions.upsert = true; - - // We have a user, let's update the password or upsert if not - updateOne( - collection, - { user: username }, - { $set: { user: username, pwd: userPassword } }, - finalOptions, - err => { - if (count === 0 && err) - return handleCallback(callback, null, [{ user: username, pwd: userPassword }]); - if (err) return handleCallback(callback, err, null); - handleCallback(callback, null, [{ user: username, pwd: userPassword }]); - } - ); - }); + collection.find({ user: username }, finalOptions).toArray(err => { + // We got an error (f.ex not authorized) + if (err != null) return handleCallback(callback, err, null); + // Add command keys + finalOptions.upsert = true; + + // We have a user, let's update the password or upsert if not + updateOne( + collection, + { user: username }, + { $set: { user: username, pwd: userPassword } }, + finalOptions, + err => { + if (count === 0 && err) + return handleCallback(callback, null, [{ user: username, pwd: userPassword }]); + if (err) return handleCallback(callback, err, null); + handleCallback(callback, null, [{ user: username, pwd: userPassword }]); + } + ); + }); }); return; From 14759c94e67df850adb1fa88dfc80cfa178852c7 Mon Sep 17 00:00:00 2001 From: Katherine Walker Date: Tue, 31 Jul 2018 10:37:50 -0400 Subject: [PATCH 3/4] do not modify finalOptions --- lib/operations/db_ops.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/operations/db_ops.js b/lib/operations/db_ops.js index 4b8a122a67..c7b48eac76 100644 --- a/lib/operations/db_ops.js +++ b/lib/operations/db_ops.js @@ -90,8 +90,9 @@ function addUser(db, username, password, options, callback) { // We got an error (f.ex not authorized) if (err != null) return handleCallback(callback, err, null); // Check if the user exists and update i - finalOptions.projection = { dbName: 1 }; - collection.find({ user: username }, finalOptions).toArray(err => { + let findOptions = finalOptions; + findOptions.projection = { dbName: 1 }; + collection.find({ user: username }, findOptions).toArray(err => { // We got an error (f.ex not authorized) if (err != null) return handleCallback(callback, err, null); // Add command keys From 6f9750220a751c9e36908bc7bdcb315e0c90ea00 Mon Sep 17 00:00:00 2001 From: Katherine Walker Date: Wed, 8 Aug 2018 10:55:56 -0400 Subject: [PATCH 4/4] incorporate feedback --- lib/operations/db_ops.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/operations/db_ops.js b/lib/operations/db_ops.js index c7b48eac76..af0210a97b 100644 --- a/lib/operations/db_ops.js +++ b/lib/operations/db_ops.js @@ -90,8 +90,7 @@ function addUser(db, username, password, options, callback) { // We got an error (f.ex not authorized) if (err != null) return handleCallback(callback, err, null); // Check if the user exists and update i - let findOptions = finalOptions; - findOptions.projection = { dbName: 1 }; + const findOptions = Object.assign({ projection: { dbName: 1 } }, finalOptions); collection.find({ user: username }, findOptions).toArray(err => { // We got an error (f.ex not authorized) if (err != null) return handleCallback(callback, err, null);