@@ -15,7 +15,7 @@ const toError = require('../utils').toError;
15
15
const count = require ( './collection_ops' ) . count ;
16
16
const findOne = require ( './collection_ops' ) . findOne ;
17
17
const remove = require ( './collection_ops' ) . remove ;
18
- const update = require ( './collection_ops' ) . update ;
18
+ const updateOne = require ( './collection_ops' ) . updateOne ;
19
19
20
20
const debugFields = [
21
21
'authSource' ,
@@ -90,28 +90,27 @@ function addUser(db, username, password, options, callback) {
90
90
// We got an error (f.ex not authorized)
91
91
if ( err != null ) return handleCallback ( callback , err , null ) ;
92
92
// 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
+ } ) ;
115
114
} ) ;
116
115
117
116
return ;
@@ -592,7 +591,7 @@ function profilingInfo(db, options, callback) {
592
591
try {
593
592
db
594
593
. collection ( 'system.profile' )
595
- . find ( { } , null , options )
594
+ . find ( { } , options )
596
595
. toArray ( callback ) ;
597
596
} catch ( err ) {
598
597
return callback ( err , null ) ;
0 commit comments