119 x 32 1 Hidden Terminal give me a title: MongoServerError during import: "Given transaction number does not match any in-progress transactions"



  • Hello,
    I'm running into a MongoDB transaction error when using the import API and I wanted to report it in case it's a known issue or something worth looking into.

    Environment
    jsreport: 4.12.0
    @jsreport/jsreport-core: 4.9.0
    @jsreport/jsreport-import-export: 4.1.0
    @jsreport/jsreport-mongodb-store: 4.0.0
    mongodb driver: 6.6.2
    MongoDB: Replica Set (Azure Atlas)
    Store provider: mongodb
    What happens
    When calling POST /api/import to import a .jsrexport file, the import fails with:

    MongoServerError: Given transaction number 1 does not match any in-progress transactions. The active transaction number is -1
    

    The error is logged as:

    warn: Unable to insert an entity (folders) "/OUR_FOLDER" during the import: MongoServerError: Given transaction number 1 does not match any in-progress transactions. The active transaction number is -1
    

    How to reproduce

    1. Configure jsreport with store.provider: "mongodb" on a replica set
    2. Delete several top-level folders containing many child entities (templates, scripts, assets) via the OData API
    3. Wait ~few seconds
    4. Call POST /api/import with a zip file that re-creates those same folders and entities

    The import fails with the transaction error above

    What I found
    The error originates from the transaction block in @jsreport/jsreport-import-export/lib/import/index.js (around lines 294-310), where beginTransaction is called and then entity records are persisted sequentially inside the transaction.

    It seems like MongoDB is rejecting the write operations within the transaction due to a conflict with the recently completed delete operations on the same collections. The transaction number -1 indicates the server considers no transaction to be active, even though the client session believes one is in progress.

    I also noticed that, in our case, the import appeared to succeed from the caller's perspective (our code was not checking the HTTP response status — that's on us and we've fixed it). But I wanted to flag the underlying transaction issue since it could affect other users as well.


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.