Hi, all! I’m new to MongoDB and am hoping to see if anyone on here has run into some of the issues I’m having.
Just to provide some context, I am developing a desktop application that monitors changes to a MongoDB hosted locally. This MongoDB is initialized and maintained as a standalone database from another desktop application.
I came across the watch()
APIs that create Change Streams that may be used to access changes to the database. After running the application, I received this error:
com.mongodb.MongoCommandException: Command failed with error 40573 (Location40573): 'The $changeStream stage is only supported on replica sets' on server localhost:27017. The full response is {"ok": 0.0, "errmsg": "The $changeStream stage is only supported on replica sets", "code": 40573, "codeName": "Location40573"}
So naturally, I dug into this a bit. It looks like Change Streams only work if the database is initialized as a replica set. I was able to shutdown the database (which, again, was initialized by a separate desktop application) and re-initialize it using the --replSet rs0
option. After running my application again, everything worked! It seems I’ve created a single-node replication set just so that the Change Streams can have access to the oplog?
I guess my question is based on how the Change Streams work. Am I correct to assume that the Change Streams monitor the oplog directly, and the only way that oplog is created is by initializing the database as a replication set?
If this assumption is correct, does anyone know of any other way to create the oplog without having to initialize the database as a replication set?
Or can I monitor updates to the oplog directly? I’m assuming that might be a huge pain, which is probably why the Change Streams exist in the first place.
Thanks all for your help! Let me know if you need more context!