@@ -226,4 +226,46 @@ describe('Find and Modify', function() {
226
226
} ) ;
227
227
}
228
228
} ) ;
229
+
230
+ it ( 'should honor ignoreUndefined on all findAndModify commands' , function ( done ) {
231
+ const configuration = this . configuration ;
232
+ const client = configuration . newClient ( { } , { ignoreUndefined : true } ) ;
233
+ client . connect ( ( err , client ) => {
234
+ expect ( err ) . to . be . null ;
235
+ const db = client . db ( configuration . db ) ;
236
+ const collection = db . collection ( 'findAndModifyIgnoreUndefined' ) ;
237
+ collection . findOneAndUpdate (
238
+ { test : 'test' } ,
239
+ {
240
+ $set : { undefined_1 : undefined , null_1 : null } ,
241
+ $setOnInsert : { undefined_2 : undefined , null_2 : null }
242
+ } ,
243
+ { upsert : true } ,
244
+ err => {
245
+ expect ( err ) . to . be . null ;
246
+ collection . findOne ( { test : 'test' } , ( err , result ) => {
247
+ expect ( err ) . to . not . exist ;
248
+ expect ( result ) . to . have . property ( 'null_1' , null ) ;
249
+ expect ( result ) . to . not . have . property ( 'undefined_1' ) ;
250
+ expect ( result ) . to . have . property ( 'null_2' , null ) ;
251
+ expect ( result ) . to . not . have . property ( 'undefined_2' ) ;
252
+ collection . findOneAndReplace (
253
+ { test : 'test' } ,
254
+ { test : 'test' , undefined_3 : undefined , null_3 : null } ,
255
+ ( err , result ) => {
256
+ expect ( err ) . to . not . exist ;
257
+ expect ( result ) . to . exist ;
258
+ collection . findOne ( { test : 'test' } , ( err , result ) => {
259
+ expect ( err ) . to . not . exist ;
260
+ expect ( result ) . to . have . property ( 'null_3' , null ) ;
261
+ expect ( result ) . to . not . have . property ( 'undefined_3' ) ;
262
+ client . close ( done ) ;
263
+ } ) ;
264
+ }
265
+ ) ;
266
+ } ) ;
267
+ }
268
+ ) ;
269
+ } ) ;
270
+ } ) ;
229
271
} ) ;
0 commit comments