[SERVER-77256] Unable to read from a snapshot due to pending collection catalog changes; please retry Created: 18/May/23  Updated: 27/Oct/23  Resolved: 27/Oct/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 5.0.18
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Elias Soykat Assignee: Backlog - Triage Team
Resolution: Done Votes: 0
Labels: mongoose, session, transactions
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Server Triage
Operating System: ALL
Steps To Reproduce:

```js
try

{     const session = await mongoose.startSession();     session.startTransaction();      const createPages = await CollectionA.insertMany(newPages, \{ session }

);

     const pageIds = cratePages.map((page) => page.id);

     await  CollectionB.findByIdAndUpdate(
            Id,
            { $set:

{ firstName: "John Doe" }

, $push: { pages:

{ $each: pageIds }

} },
            { session }

    if (isDelete) {
         await CollectionA.deleteMany({ _id:

{ $in:[1, 2, 3, 4, 5] }

}, { session });
       }

 

    if (!cratePages || !updateSite)

{         await session.abortTransaction();         await session.endSession();         return null;       }

     await session.commitTransaction();
      await session.endSession();

      return cratePages;

} catch(err)

{      await session.abortTransaction();      await session.endSession();       throw err; }

``` 

Participants:

 Description   
      1. Prerequisites
  • [X] I have written a descriptive issue title
      1. Mongoose version

5.12

      1. Node.js version

18

      1. MongoDB version

6

      1. Operating system

macOS

      1. Operating system version (i.e. 20.04, 11.3, 10)

13

      1. Issue

Hey there!

I'm using mongodb transaction over the operation. I insert many documents using `insertMany` in `CollectionA` then i $set and $push CollectionA ids in `CollectionB` a particular fields.  then finally i delete few specific documents from `CollectionA`

Lets share an example : 

try {
    const session = await mongoose.startSession();
    session.startTransaction();
 
 
     const createPages = await CollectionA.insertMany(newPages, \{ session });
 
     const pageIds = cratePages.map((page) => page.id);
 
 
     await  CollectionB.findByIdAndUpdate(
            Id,
            \{ $set: { firstName: "John Doe" }, $push: \{ pages: { $each: pageIds } } },
            \{ session }
 
 
    if (isDelete) {
         await CollectionA.deleteMany(\{ _id: { $in:[1, 2, 3, 4, 5] } }, \{ session });
       }
 
 
 
 
    if (!cratePages || !updateSite) {
        await session.abortTransaction();
        await session.endSession();
        return null;
      }
 
 
     await session.commitTransaction();
      await session.endSession();
 
      return cratePages;
 
} catch(err){
     await session.abortTransaction();
     await session.endSession();
      throw err;
 
}

 

This is a graphql api. after running this api it's seems work perfectly but when i test this resolvers code using `mocha` and `chai.js` but when i run the test some times I passed the test (means work) and some times test throw bellow error

`
MongoError: Unable to read from a snapshot due to pending collection catalog changes; please retry the operation.Snapshot timestamp is Timestamp(1684396773, 34).Collection minimum is Timestamp(1684396773, 36)
 at MessageStream.messageHandler(/usr/src / app / node_modules / mongodb / lib / cmap / connection.js: 299: 20)
 at MessageStream.emit(node: events: 513: 28)
 at MessageStream.emit(node: domain: 489: 12)
 at processIncomingData(/usr/src / app / node_modules / mongodb / lib / cmap / message_stream.js: 144: 12)
 at MessageStream._write(/usr/src / app / node_modules / mongodb / lib / cmap / message_stream.js: 42: 5)
 at writeOrBuffer(node: internal / streams / writable: 392: 12)
 at _write(node: internal / streams / writable: 333: 10)
 at Writable.write(node: internal / streams / writable: 337: 10)
 at Socket.ondata(node: internal / streams / readable: 766: 22)
 at Socket.emit(node: events: 513: 28)
 at Socket.emit(node: domain: 489: 12)
 at addChunk(node: internal / streams / readable: 324: 12)
 at readableAddChunk(node: internal / streams / readable: 297: 9)
 at Readable.push(node: internal / streams / readable: 234: 10)
 at TCP.onStreamRead(node: internal / stream_base_commons: 190: 23)

{    operationTime: Timestamp \{ _bsontype: 'Timestamp', low_: 36, high_: 1684396773 }

,
   ok: 0,
     code: 246,
       codeName: 'SnapshotUnavailable',
         '$clusterTime':

{      clusterTime: Timestamp \{ _bsontype: 'Timestamp', low_: 36, high_: 1684396773 }

,
     signature: { hash: [Binary], keyId: 0 }
       },
   [Symbol(errorLabels)]: Set(1) { 'TransientTransactionError' }
   }
`



 Comments   
Comment by Edwin Zhou [ 27/Oct/23 ]

Hi eliasmd624@gmail.com,

For this issue we'd like to encourage you to start by asking our community for help by posting on the MongoDB Developer Community Forums.

If the discussion there leads you to suspect a bug in the MongoDB server, then we'd want to investigate it as a possible bug here in the SERVER project.

Kind regards,
Edwin

Generated at Thu Feb 08 06:34:58 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.