Issue around usage of startAtOperationTime in change streams

Hey i am making use of mongodb npm package: “mongodb”: “^4.1.3” – i am making use of documentdb and not mongo db directly.

Documentdb v4 claims to introduce the Change Streams functionality with startAtOperationTime functionality.

I am trying to make use of startAtOperationTime for the change stream option, but it i isn’t working.

 const shadowCollection = await DOCUMENT_DB.collection(COLLECTION_NAME, {
      readPreference: 'primary'
    });

    const changeStream = shadowCollection.watch([], {
      startAtOperationTime:
        Timestamp.fromString(new Date(1646137220562).toString())  // if we do not pass this option then it works fine
    });

    await changeStream.hasNext()  // this line throws the error

Error is: MongoError: modifyChangeStreams has not been run for this collection/database/cluster

And i have enabled the change streams on this particular database and collection.

Anything that i am doing wrong? Or some other suggestions

Hi @Sujay_Venaik welcome to the community!

Unfortunately we can’t really help you there, since although DocumentDB claims compatibility with MongoDB, there is no way to confirm that any feature they advertise actually does work. Since officially supported MongoDB drivers are designed to work with genuine MongoDB servers, it wouldn’t surprise me if some features do not work as advertised with non-genuine MongoDB servers.

I would encourage you to try MongoDB Atlas instead, as it would guarantee 100% compatibility with all official drivers, and protect you from surprises like this (or worse) in the future.

Best regards
Kevin

1 Like