1- import { BSON , type Document } from '../../bson' ;
1+ import { BSON , type BSONSerializeOptions , type Document } from '../../bson' ;
22import { DocumentSequence } from '../../cmap/commands' ;
33import { MongoAPIError , MongoInvalidArgumentError } from '../../error' ;
44import { type PkFactory } from '../../mongo_client' ;
@@ -128,7 +128,7 @@ export class ClientBulkWriteCommandBuilder {
128128
129129 if ( nsIndex != null ) {
130130 // 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 ) ;
132132 let operationBuffer ;
133133 try {
134134 operationBuffer = BSON . serialize ( operation ) ;
@@ -159,7 +159,12 @@ export class ClientBulkWriteCommandBuilder {
159159 // construct our nsInfo and ops documents and buffers.
160160 namespaces . set ( ns , currentNamespaceIndex ) ;
161161 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+ ) ;
163168 let nsInfoBuffer ;
164169 let operationBuffer ;
165170 try {
@@ -339,9 +344,10 @@ export interface ClientUpdateOperation {
339344 */
340345export const buildUpdateOneOperation = (
341346 model : ClientUpdateOneModel < Document > ,
342- index : number
347+ index : number ,
348+ options : BSONSerializeOptions
343349) : ClientUpdateOperation => {
344- return createUpdateOperation ( model , index , false ) ;
350+ return createUpdateOperation ( model , index , false , options ) ;
345351} ;
346352
347353/**
@@ -352,17 +358,18 @@ export const buildUpdateOneOperation = (
352358 */
353359export const buildUpdateManyOperation = (
354360 model : ClientUpdateManyModel < Document > ,
355- index : number
361+ index : number ,
362+ options : BSONSerializeOptions
356363) : ClientUpdateOperation => {
357- return createUpdateOperation ( model , index , true ) ;
364+ return createUpdateOperation ( model , index , true , options ) ;
358365} ;
359366
360367/**
361368 * Validate the update document.
362369 * @param update - The update document.
363370 */
364- function validateUpdate ( update : Document ) {
365- if ( ! hasAtomicOperators ( update ) ) {
371+ function validateUpdate ( update : Document , options : BSONSerializeOptions ) {
372+ if ( ! hasAtomicOperators ( update , options ) ) {
366373 throw new MongoAPIError (
367374 'Client bulk write update models must only contain atomic modifiers (start with $) and must not be empty.'
368375 ) ;
@@ -375,13 +382,14 @@ function validateUpdate(update: Document) {
375382function createUpdateOperation (
376383 model : ClientUpdateOneModel < Document > | ClientUpdateManyModel < Document > ,
377384 index : number ,
378- multi : boolean
385+ multi : boolean ,
386+ options : BSONSerializeOptions
379387) : ClientUpdateOperation {
380388 // Update documents provided in UpdateOne and UpdateMany write models are
381389 // required only to contain atomic modifiers (i.e. keys that start with "$").
382390 // Drivers MUST throw an error if an update document is empty or if the
383391 // document's first key does not start with "$".
384- validateUpdate ( model . update ) ;
392+ validateUpdate ( model . update , options ) ;
385393 const document : ClientUpdateOperation = {
386394 update : index ,
387395 multi : multi ,
@@ -459,7 +467,8 @@ export const buildReplaceOneOperation = (
459467export function buildOperation (
460468 model : AnyClientBulkWriteModel < Document > ,
461469 index : number ,
462- pkFactory : PkFactory
470+ pkFactory : PkFactory ,
471+ options : BSONSerializeOptions
463472) : Document {
464473 switch ( model . name ) {
465474 case 'insertOne' :
@@ -469,9 +478,9 @@ export function buildOperation(
469478 case 'deleteMany' :
470479 return buildDeleteManyOperation ( model , index ) ;
471480 case 'updateOne' :
472- return buildUpdateOneOperation ( model , index ) ;
481+ return buildUpdateOneOperation ( model , index , options ) ;
473482 case 'updateMany' :
474- return buildUpdateManyOperation ( model , index ) ;
483+ return buildUpdateManyOperation ( model , index , options ) ;
475484 case 'replaceOne' :
476485 return buildReplaceOneOperation ( model , index ) ;
477486 }
0 commit comments