8
8
MongoDBNamespace ,
9
9
Callback
10
10
} from './utils' ;
11
- import { ObjectId , Document , BSONSerializeOptions } from './bson' ;
11
+ import { ObjectId , Document , BSONSerializeOptions , resolveBSONOptions } from './bson' ;
12
12
import { MongoError } from './error' ;
13
13
import { UnorderedBulkOperation } from './bulk/unordered' ;
14
14
import { OrderedBulkOperation } from './bulk/ordered' ;
@@ -127,13 +127,8 @@ export interface CollectionPrivate {
127
127
options : any ;
128
128
namespace : MongoDBNamespace ;
129
129
readPreference ?: ReadPreference ;
130
+ bsonOptions : BSONSerializeOptions ;
130
131
slaveOk ?: boolean ;
131
- serializeFunctions ?: boolean ;
132
- raw ?: boolean ;
133
- promoteLongs ?: boolean ;
134
- promoteValues ?: boolean ;
135
- promoteBuffers ?: boolean ;
136
- ignoreUndefined ?: boolean ;
137
132
collectionHint ?: Hint ;
138
133
readConcern ?: ReadConcern ;
139
134
writeConcern ?: WriteConcern ;
@@ -189,30 +184,10 @@ export class Collection implements OperationParent {
189
184
}
190
185
} ,
191
186
readPreference : ReadPreference . fromOptions ( options ) ,
187
+ bsonOptions : resolveBSONOptions ( options , db ) ,
192
188
readConcern : ReadConcern . fromOptions ( options ) ,
193
189
writeConcern : WriteConcern . fromOptions ( options ) ,
194
- slaveOk : options == null || options . slaveOk == null ? db . slaveOk : options . slaveOk ,
195
- serializeFunctions :
196
- options == null || options . serializeFunctions == null
197
- ? db . s . options ?. serializeFunctions
198
- : options . serializeFunctions ,
199
- raw : options == null || options . raw == null ? db . s . options ?. raw : options . raw ,
200
- promoteLongs :
201
- options == null || options . promoteLongs == null
202
- ? db . s . options ?. promoteLongs
203
- : options . promoteLongs ,
204
- promoteValues :
205
- options == null || options . promoteValues == null
206
- ? db . s . options ?. promoteValues
207
- : options . promoteValues ,
208
- promoteBuffers :
209
- options == null || options . promoteBuffers == null
210
- ? db . s . options ?. promoteBuffers
211
- : options . promoteBuffers ,
212
- ignoreUndefined :
213
- options == null || options . ignoreUndefined == null
214
- ? db . s . options ?. ignoreUndefined
215
- : options . ignoreUndefined
190
+ slaveOk : options == null || options . slaveOk == null ? db . slaveOk : options . slaveOk
216
191
} ;
217
192
}
218
193
@@ -261,6 +236,10 @@ export class Collection implements OperationParent {
261
236
return this . s . readPreference ;
262
237
}
263
238
239
+ get bsonOptions ( ) : BSONSerializeOptions {
240
+ return this . s . bsonOptions ;
241
+ }
242
+
264
243
/**
265
244
* The current writeConcern of the collection. If not explicitly defined for
266
245
* this collection, will be inherited from the parent DB
@@ -302,12 +281,6 @@ export class Collection implements OperationParent {
302
281
if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
303
282
options = options || { } ;
304
283
305
- // Add ignoreUndefined
306
- if ( this . s . options . ignoreUndefined ) {
307
- options = Object . assign ( { } , options ) ;
308
- options . ignoreUndefined = this . s . options . ignoreUndefined ;
309
- }
310
-
311
284
return executeOperation ( this . s . topology , new InsertOneOperation ( this , doc , options ) , callback ) ;
312
285
}
313
286
@@ -429,12 +402,6 @@ export class Collection implements OperationParent {
429
402
if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
430
403
options = Object . assign ( { } , options ) ;
431
404
432
- // Add ignoreUndefined
433
- if ( this . s . options . ignoreUndefined ) {
434
- options = Object . assign ( { } , options ) ;
435
- options . ignoreUndefined = this . s . options . ignoreUndefined ;
436
- }
437
-
438
405
return executeOperation (
439
406
this . s . topology ,
440
407
new UpdateOneOperation ( this , filter , update , options ) ,
@@ -472,12 +439,6 @@ export class Collection implements OperationParent {
472
439
if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
473
440
options = Object . assign ( { } , options ) ;
474
441
475
- // Add ignoreUndefined
476
- if ( this . s . options . ignoreUndefined ) {
477
- options = Object . assign ( { } , options ) ;
478
- options . ignoreUndefined = this . s . options . ignoreUndefined ;
479
- }
480
-
481
442
return executeOperation (
482
443
this . s . topology ,
483
444
new ReplaceOneOperation ( this , filter , replacement , options ) ,
@@ -511,12 +472,6 @@ export class Collection implements OperationParent {
511
472
if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
512
473
options = Object . assign ( { } , options ) ;
513
474
514
- // Add ignoreUndefined
515
- if ( this . s . options . ignoreUndefined ) {
516
- options = Object . assign ( { } , options ) ;
517
- options . ignoreUndefined = this . s . options . ignoreUndefined ;
518
- }
519
-
520
475
return executeOperation (
521
476
this . s . topology ,
522
477
new UpdateManyOperation ( this , filter , update , options ) ,
@@ -543,12 +498,6 @@ export class Collection implements OperationParent {
543
498
if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
544
499
options = Object . assign ( { } , options ) ;
545
500
546
- // Add ignoreUndefined
547
- if ( this . s . options . ignoreUndefined ) {
548
- options = Object . assign ( { } , options ) ;
549
- options . ignoreUndefined = this . s . options . ignoreUndefined ;
550
- }
551
-
552
501
return executeOperation (
553
502
this . s . topology ,
554
503
new DeleteOneOperation ( this , filter , options ) ,
@@ -587,12 +536,6 @@ export class Collection implements OperationParent {
587
536
588
537
options = Object . assign ( { } , options ) ;
589
538
590
- // Add ignoreUndefined
591
- if ( this . s . options . ignoreUndefined ) {
592
- options = Object . assign ( { } , options ) ;
593
- options . ignoreUndefined = this . s . options . ignoreUndefined ;
594
- }
595
-
596
539
return executeOperation (
597
540
this . s . topology ,
598
541
new DeleteManyOperation ( this , filter , options ) ,
@@ -1345,7 +1288,7 @@ export class Collection implements OperationParent {
1345
1288
options = options || { } ;
1346
1289
// Give function's options precedence over session options.
1347
1290
if ( options . ignoreUndefined == null ) {
1348
- options . ignoreUndefined = this . s . options . ignoreUndefined ;
1291
+ options . ignoreUndefined = this . bsonOptions . ignoreUndefined ;
1349
1292
}
1350
1293
1351
1294
return new UnorderedBulkOperation ( this , options ) ;
@@ -1356,7 +1299,7 @@ export class Collection implements OperationParent {
1356
1299
options = options || { } ;
1357
1300
// Give function's options precedence over session's options.
1358
1301
if ( options . ignoreUndefined == null ) {
1359
- options . ignoreUndefined = this . s . options . ignoreUndefined ;
1302
+ options . ignoreUndefined = this . bsonOptions . ignoreUndefined ;
1360
1303
}
1361
1304
1362
1305
return new OrderedBulkOperation ( this , options ) ;
@@ -1415,12 +1358,6 @@ export class Collection implements OperationParent {
1415
1358
if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
1416
1359
options = options || { } ;
1417
1360
1418
- // Add ignoreUndefined
1419
- if ( this . s . options . ignoreUndefined ) {
1420
- options = Object . assign ( { } , options ) ;
1421
- options . ignoreUndefined = this . s . options . ignoreUndefined ;
1422
- }
1423
-
1424
1361
return this . updateMany ( selector , update , options , callback ) ;
1425
1362
}
1426
1363
@@ -1440,12 +1377,6 @@ export class Collection implements OperationParent {
1440
1377
if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
1441
1378
options = options || { } ;
1442
1379
1443
- // Add ignoreUndefined
1444
- if ( this . s . options . ignoreUndefined ) {
1445
- options = Object . assign ( { } , options ) ;
1446
- options . ignoreUndefined = this . s . options . ignoreUndefined ;
1447
- }
1448
-
1449
1380
return this . deleteMany ( selector , options , callback ) ;
1450
1381
}
1451
1382
0 commit comments