Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-1843

Bulk operation executes outside provided session transaction

    XMLWordPrintable

    Details

    • Story Points:
      5
    • Case:
    • Documentation Changes:
      Not Needed

      Description

      Hello,

      Bulk operation created via initializeOrderedBulkOp or initializeUnorderedBulkOp does not support MongoDB transactions. According to the documentation a client session (with started transaction) can be passed as an option to the collection methods mentioned above, however created bulk operations do not seem to be executed within a passed session transaction. Please review the test case below (also added to the issue attachments).

      "use strict";
       
      const { expect } = require ('chai')
      const { MongoClient } = require ('mongodb')
       
      let client = undefined
       
      describe ('Bulk operation transaction rollback', () => {
       
          before (async () => client = await MongoClient.connect ('mongodb://localhost:27017', { useNewUrlParser: true }))
          after (() => client.close ())
       
          it ('should abort ordered/unordered bulk operation writes', async () => {
       
              const collection = client.db ('Test').collection ('bulk_write_transaction_test')
              await collection.deleteMany ({})
       
              const session = client.startSession ()
              session.startTransaction ({
                  readConcern: { level: 'snapshot' },
                  writeConcern: { w: 'majority' },
              })
       
              let bulk = undefined
       
              // 1.
              bulk = collection.initializeUnorderedBulkOp ({ session })
              bulk.insert ({ 'answer': 42 })
              await bulk.execute ()
       
              // 2.
              bulk = collection.initializeOrderedBulkOp ({ session })
              bulk.insert ({ 'answer': 43 })
              await bulk.execute ()
       
              await session.abortTransaction ()
              await session.endSession ()
       
              const documents = await collection.find ().toArray ()
       
              expect (documents).to.be.lengthOf (0, 'bulk operation writes were made outside of transaction')
       
              return
          })
      })
      

       

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              daria.pardue Daria Pardue
              Reporter:
              takatan Den
              Implementer:
              Neal Beeken Neal Beeken
              Votes:
              2 Vote for this issue
              Watchers:
              8 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: