For databases that are not replica sets and sharded clusters, how to monitor the changes of the database in real time?

For databases that are not replica sets and sharded clusters, how to implement a similar function to db.collection.watch, that is, to monitor the changes of the database in real time?

db.collection.watch is For replica sets and sharded clusters only .

I am not sure of your requirements but perhaps the change stream will be helpful.

See https://docs.mongodb.com/manual/changeStreams/

I mean how to use Change Streams on a normal database

@masx200_masx200 Change streams require a replica set or sharded cluster deployment because the mechanism for monitoring data changes is provided by the replication oplog which does not exist in a standalone deployment.

However, you can create a single member replica set deployment for testing or development purposes. To do so, follow the tutorial to Convert a Standalone to a Replica Set but do not add any additional members after initialising the replica set.

The main downsides of a single member deployment are that you don’t get any of the usual replica set benefits such as data redundancy and fault tolerance. A replica set member also has some expected write overhead as compared to a standalone server because it has to maintain the oplog.

Regards,
Stennie

1 Like