1
- import { BSON , type Document } from '../../bson' ;
1
+ import { BSON , type BSONSerializeOptions , type Document } from '../../bson' ;
2
2
import { DocumentSequence } from '../../cmap/commands' ;
3
3
import { MongoAPIError , MongoInvalidArgumentError } from '../../error' ;
4
4
import { type PkFactory } from '../../mongo_client' ;
@@ -128,7 +128,7 @@ export class ClientBulkWriteCommandBuilder {
128
128
129
129
if ( nsIndex != null ) {
130
130
// Build the operation and serialize it to get the bytes buffer.
131
- const operation = buildOperation ( model , nsIndex , this . pkFactory ) ;
131
+ const operation = buildOperation ( model , nsIndex , this . pkFactory , this . options ) ;
132
132
let operationBuffer ;
133
133
try {
134
134
operationBuffer = BSON . serialize ( operation ) ;
@@ -159,7 +159,12 @@ export class ClientBulkWriteCommandBuilder {
159
159
// construct our nsInfo and ops documents and buffers.
160
160
namespaces . set ( ns , currentNamespaceIndex ) ;
161
161
const nsInfo = { ns : ns } ;
162
- const operation = buildOperation ( model , currentNamespaceIndex , this . pkFactory ) ;
162
+ const operation = buildOperation (
163
+ model ,
164
+ currentNamespaceIndex ,
165
+ this . pkFactory ,
166
+ this . options
167
+ ) ;
163
168
let nsInfoBuffer ;
164
169
let operationBuffer ;
165
170
try {
@@ -339,9 +344,10 @@ export interface ClientUpdateOperation {
339
344
*/
340
345
export const buildUpdateOneOperation = (
341
346
model : ClientUpdateOneModel < Document > ,
342
- index : number
347
+ index : number ,
348
+ options : BSONSerializeOptions
343
349
) : ClientUpdateOperation => {
344
- return createUpdateOperation ( model , index , false ) ;
350
+ return createUpdateOperation ( model , index , false , options ) ;
345
351
} ;
346
352
347
353
/**
@@ -352,17 +358,18 @@ export const buildUpdateOneOperation = (
352
358
*/
353
359
export const buildUpdateManyOperation = (
354
360
model : ClientUpdateManyModel < Document > ,
355
- index : number
361
+ index : number ,
362
+ options : BSONSerializeOptions
356
363
) : ClientUpdateOperation => {
357
- return createUpdateOperation ( model , index , true ) ;
364
+ return createUpdateOperation ( model , index , true , options ) ;
358
365
} ;
359
366
360
367
/**
361
368
* Validate the update document.
362
369
* @param update - The update document.
363
370
*/
364
- function validateUpdate ( update : Document ) {
365
- if ( ! hasAtomicOperators ( update ) ) {
371
+ function validateUpdate ( update : Document , options : BSONSerializeOptions ) {
372
+ if ( ! hasAtomicOperators ( update , options ) ) {
366
373
throw new MongoAPIError (
367
374
'Client bulk write update models must only contain atomic modifiers (start with $) and must not be empty.'
368
375
) ;
@@ -375,13 +382,14 @@ function validateUpdate(update: Document) {
375
382
function createUpdateOperation (
376
383
model : ClientUpdateOneModel < Document > | ClientUpdateManyModel < Document > ,
377
384
index : number ,
378
- multi : boolean
385
+ multi : boolean ,
386
+ options : BSONSerializeOptions
379
387
) : ClientUpdateOperation {
380
388
// Update documents provided in UpdateOne and UpdateMany write models are
381
389
// required only to contain atomic modifiers (i.e. keys that start with "$").
382
390
// Drivers MUST throw an error if an update document is empty or if the
383
391
// document's first key does not start with "$".
384
- validateUpdate ( model . update ) ;
392
+ validateUpdate ( model . update , options ) ;
385
393
const document : ClientUpdateOperation = {
386
394
update : index ,
387
395
multi : multi ,
@@ -459,7 +467,8 @@ export const buildReplaceOneOperation = (
459
467
export function buildOperation (
460
468
model : AnyClientBulkWriteModel < Document > ,
461
469
index : number ,
462
- pkFactory : PkFactory
470
+ pkFactory : PkFactory ,
471
+ options : BSONSerializeOptions
463
472
) : Document {
464
473
switch ( model . name ) {
465
474
case 'insertOne' :
@@ -469,9 +478,9 @@ export function buildOperation(
469
478
case 'deleteMany' :
470
479
return buildDeleteManyOperation ( model , index ) ;
471
480
case 'updateOne' :
472
- return buildUpdateOneOperation ( model , index ) ;
481
+ return buildUpdateOneOperation ( model , index , options ) ;
473
482
case 'updateMany' :
474
- return buildUpdateManyOperation ( model , index ) ;
483
+ return buildUpdateManyOperation ( model , index , options ) ;
475
484
case 'replaceOne' :
476
485
return buildReplaceOneOperation ( model , index ) ;
477
486
}
0 commit comments