MongoDB.live, free & fully virtual. June 9th - 10th. Register Now MongoDB.live, free & fully virtual. June 9th - 10th. Register Now

Syncing Collections from different servers

Hi all,

I would like to compare and sync collections manually and automatically. By syncing, I mean adding new documents to the target DB and removing obsolete documents from it.
I have found 2 tools, that seem to do the job, at least manually:

https://studio3t.com/knowledge-base/articles/compare-mongodb-collections/?utm_source=post&utm_medium=fb&utm_campaign=3tslpage
https://mingo.io/feature/compare-n-sync

Are there any other ways to do it? If possible by using free tools.

What is the purpose of this?

Replica set already sync the data from primary to secondary servers.

However if you want an offline copy I would recommend to use https://docs.mongodb.com/manual/reference/program/mongodump/

and check this page out https://docs.mongodb.com/manual/tutorial/backup-and-restore-tools/

Thanks for the answers!

@steevej

What is the purpose of this?

I don’t think it’s necessary but I’ll give an example: 2 mongoDB servers A,B which in the beginning are synced with some blogs. On server A new blogs are being added or removed. I would like to know which of them were added and which were removed in comparison to server B. Then accordingly add them or removed them from B. Simple.

Replica set already sync the data from primary to secondary servers.

No, I don’t mean replication.

@coderkid: I did not tried it yet, but the idea now is to use mongoexport to export the collections in subsequent times in JSON format and compare the JSON files. Then import or remove the documents from the other server depending on the diff file.

Thanks. Your explications help provide a better answer. I think you will like what the change stream API provides. Take a look at https://docs.mongodb.com/manual/changeStreams/

@steevej:
Thanks. It looks interesting.