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

Change stream should pass both resumeAfter and startAtOperationTime

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 3.1.0
    • Affects Version/s: None
    • Component/s: Native
    • None

      From the change streams spec:

      startAtOperationTime and resumeAfter are mutually exclusive; if both startAtOperationTime and resumeAfter are set, the server will return an error. Drivers MUST NOT throw a custom error, and MUST defer to the server error.

      Currently, if a user specifies resumeAfter and startAtOperationTime, it looks like only the resumeAfter token is sent. Based on the spec, both should be passed so the server can return an error.

      Here's a silly repro:

      const MongoClient = require('./node-mongodb-native').MongoClient;
      
      MongoClient.connect("mongodb://localhost:27017/?replicaSet=rs", { useNewUrlParser: true }).then((client) => {
          const db = client.db('test');
          const session = client.startSession();
          /* do something to set an operation time on the session. */
          db.collection('test').find({}, { session: session });
          const changeStream = db.collection('test').watch([], {
              session: session,
              startAtOperationTime: session.operationTime,
          });
          changeStream.on('change', (change) => {
              const cachedResumeToken = change["_id"];
              console.log('start another change stream');
              const secondChangeStream = db.collection('test').watch([], {
                  session: session,
                  startAtOperationTime: session.operationTime,
                  resumeAfter: cachedResumeToken
              });
              secondChangeStream.on('change', (change) => {
                  console.log('second change stream got', change);
              });
              changeStream.close();
          });
      });
      

            Assignee:
            daniel.aprahamian@mongodb.com Daniel Aprahamian (Inactive)
            Reporter:
            kevin.albertson@mongodb.com Kevin Albertson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: