@@ -15,7 +15,7 @@ const toError = require('../utils').toError;
1515const count = require ( './collection_ops' ) . count ;
1616const findOne = require ( './collection_ops' ) . findOne ;
1717const remove = require ( './collection_ops' ) . remove ;
18- const update = require ( './collection_ops' ) . update ;
18+ const updateOne = require ( './collection_ops' ) . updateOne ;
1919
2020const debugFields = [
2121 'authSource' ,
@@ -90,28 +90,27 @@ function addUser(db, username, password, options, callback) {
9090 // We got an error (f.ex not authorized)
9191 if ( err != null ) return handleCallback ( callback , err , null ) ;
9292 // Check if the user exists and update i
93- collection
94- . find ( { user : username } , { dbName : options [ 'dbName' ] } , finalOptions )
95- . toArray ( err => {
96- // We got an error (f.ex not authorized)
97- if ( err != null ) return handleCallback ( callback , err , null ) ;
98- // Add command keys
99- finalOptions . upsert = true ;
100-
101- // We have a user, let's update the password or upsert if not
102- update (
103- collection ,
104- { user : username } ,
105- { $set : { user : username , pwd : userPassword } } ,
106- finalOptions ,
107- err => {
108- if ( count === 0 && err )
109- return handleCallback ( callback , null , [ { user : username , pwd : userPassword } ] ) ;
110- if ( err ) return handleCallback ( callback , err , null ) ;
111- handleCallback ( callback , null , [ { user : username , pwd : userPassword } ] ) ;
112- }
113- ) ;
114- } ) ;
93+ const findOptions = Object . assign ( { projection : { dbName : 1 } } , finalOptions ) ;
94+ collection . find ( { user : username } , findOptions ) . toArray ( err => {
95+ // We got an error (f.ex not authorized)
96+ if ( err != null ) return handleCallback ( callback , err , null ) ;
97+ // Add command keys
98+ finalOptions . upsert = true ;
99+
100+ // We have a user, let's update the password or upsert if not
101+ updateOne (
102+ collection ,
103+ { user : username } ,
104+ { $set : { user : username , pwd : userPassword } } ,
105+ finalOptions ,
106+ err => {
107+ if ( count === 0 && err )
108+ return handleCallback ( callback , null , [ { user : username , pwd : userPassword } ] ) ;
109+ if ( err ) return handleCallback ( callback , err , null ) ;
110+ handleCallback ( callback , null , [ { user : username , pwd : userPassword } ] ) ;
111+ }
112+ ) ;
113+ } ) ;
115114 } ) ;
116115
117116 return ;
@@ -592,7 +591,7 @@ function profilingInfo(db, options, callback) {
592591 try {
593592 db
594593 . collection ( 'system.profile' )
595- . find ( { } , null , options )
594+ . find ( { } , options )
596595 . toArray ( callback ) ;
597596 } catch ( err ) {
598597 return callback ( err , null ) ;
0 commit comments