How to apply create/delete index ops to mirror replicaSet

In my previous role, I was developing cutting-edge MongoDB tools. One of the tools I built was jaraco.mongodb, which provides abstractions over some high- and low-level functions in MongoDB. One of the features is the oplog module (docs), which allows tailing an oplog or replaying it to another replica set.

With recent releases of MongoDB (4.2 or 4.4), one of the tests started failing. This test creates and deletes an index and asserts that the index gets created and deleted in the destination replica set, but with late versions of MongoDB fails with the error, “pymongo.errors.OperationFailure: The createIndexes operation is not supported in applyOps mode”.

Can you recommend a replacement behavior to continue to support that use-case?

Hi @jaraco,

Welcome to MongoDB Community forum.

I would like to introduce change stream allow applications to access real-time data changes without the complexity and risk of tailing the oplog.

I hope this answer can help you.


Hi Darshan. Thanks for the tip. In this case, the oplog module is designed to help keep two seemingly independent replica sets in sync using the same mechanisms that a replica set uses internally (applying oplog messages in an idempotent way).

Obviously, my question is about detecting the creation and deletion of indexes on a database and applying them to another.

But if I look at the documentation for change stream events, I don’t see anything there about index creation/deletion. Nor do I see anything about applying operations from a change stream to another database.

So it feels a little bit like the proposed answer is inadequate for the purpose and that even if I were to embark on rewriting the routine using change streams, I would find it doesn’t offer the most basic “apply” functionality.

It sure would be nice if the database could restore support for applying index creation/deletion operations or at least point to a resource that indicates that such behavior is intentionally disallowed where it was allowed before.

This library implements a more robust version of the mongooplog functionality that used to ship with MongoDB, but if that’s a use case that’s meant to be no longer viable, that would be an acceptable (though disappointing) outcome.

Hi Jason, it’s been a long time!

Index building changed in 4.4 with the release of the “simultaneous index builds” feature. This enables building indexes on the primary and secondaries simultaneously. An index build is committed when a majority of nodes have successfully built the index. The specific ticket that removed support is here: SERVER-41554. As that ticket mentions:

Applications previously running applyOps with an embedded createIndexes command will need to be converted to invoke the createIndexes command directly.

Hope this helps at least explain the reasoning behind the change.


That’s super helpful. Based on this guidance, I’ve put together a new release of jaraco.mongodb with a fix for the issue.


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.