@@ -420,8 +420,10 @@ export class MongoDriver implements Driver {
420420 }
421421
422422 // Pass session for transactional operations only if it exists
423- const result = options ?. session
424- ? await collection . insertOne ( mongoDoc , { session : options . session } )
423+ // Support both 'transaction' and 'session' option keys for compatibility
424+ const session = options ?. transaction || options ?. session ;
425+ const result = session
426+ ? await collection . insertOne ( mongoDoc , { session } )
425427 : await collection . insertOne ( mongoDoc ) ;
426428
427429 // Return API format document (convert _id to id)
@@ -456,8 +458,10 @@ export class MongoDriver implements Driver {
456458
457459 // Use findOneAndUpdate to return the updated document
458460 const mongoOptions : FindOneAndUpdateOptions = { returnDocument : 'after' } ;
459- if ( options ?. session ) {
460- mongoOptions . session = options . session ;
461+ // Support both 'transaction' and 'session' option keys for compatibility
462+ const session = options ?. transaction || options ?. session ;
463+ if ( session ) {
464+ mongoOptions . session = session ;
461465 }
462466
463467 const result = await collection . findOneAndUpdate (
@@ -473,8 +477,10 @@ export class MongoDriver implements Driver {
473477 async delete ( objectName : string , id : string | number , options ?: any ) {
474478 const collection = await this . getCollection ( objectName ) ;
475479 // Pass session for transactional operations only if it exists
476- const result = options ?. session
477- ? await collection . deleteOne ( { _id : this . normalizeId ( id ) } , { session : options . session } )
480+ // Support both 'transaction' and 'session' option keys for compatibility
481+ const session = options ?. transaction || options ?. session ;
482+ const result = session
483+ ? await collection . deleteOne ( { _id : this . normalizeId ( id ) } , { session } )
478484 : await collection . deleteOne ( { _id : this . normalizeId ( id ) } ) ;
479485 return result . deletedCount ;
480486 }
@@ -503,7 +509,11 @@ export class MongoDriver implements Driver {
503509 }
504510 return mongoDoc ;
505511 } ) ;
506- const result = await collection . insertMany ( mongoDocs ) ;
512+ // Support both 'transaction' and 'session' option keys for compatibility
513+ const session = options ?. transaction || options ?. session ;
514+ const result = session
515+ ? await collection . insertMany ( mongoDocs , { session } )
516+ : await collection . insertMany ( mongoDocs ) ;
507517 // Return API format (convert _id to id)
508518 return Object . values ( result . insertedIds ) . map ( id => ( { id } ) ) ;
509519 }
@@ -518,15 +528,23 @@ export class MongoDriver implements Driver {
518528 const isAtomic = Object . keys ( updateData ) . some ( k => k . startsWith ( '$' ) ) ;
519529 const update = isAtomic ? updateData : { $set : updateData } ;
520530
521- const result = await collection . updateMany ( filter , update ) ;
522- return result . modifiedCount ;
531+ // Support both 'transaction' and 'session' option keys for compatibility
532+ const session = options ?. transaction || options ?. session ;
533+ const result = session
534+ ? await collection . updateMany ( filter , update , { session } )
535+ : await collection . updateMany ( filter , update ) ;
536+ return { modifiedCount : result . modifiedCount } ;
523537 }
524538
525539 async deleteMany ( objectName : string , filters : any , options ?: any ) : Promise < any > {
526540 const collection = await this . getCollection ( objectName ) ;
527541 const filter = this . mapFilters ( filters ) ;
528- const result = await collection . deleteMany ( filter ) ;
529- return result . deletedCount ;
542+ // Support both 'transaction' and 'session' option keys for compatibility
543+ const session = options ?. transaction || options ?. session ;
544+ const result = session
545+ ? await collection . deleteMany ( filter , { session } )
546+ : await collection . deleteMany ( filter ) ;
547+ return { deletedCount : result . deletedCount } ;
530548 }
531549
532550 async aggregate ( objectName : string , pipeline : any [ ] , options ?: any ) : Promise < any [ ] > {
0 commit comments