I have two mongo collections, one which refers to the production env and the other to the testing env.
How can I compare a diff between my two collections?
I tried dumping them to a bson and then converting to a json. But I cant just perform a simple diff on them since the sorting might vary and the json file is way too large to be sorted.
Try the following in the shell, it will iterate each item within a collection and try to match each document based on ID.
Say we have 2 collections
db.col1
anddb.col2
:We can then create a javascript function to compare 2 collections
Then call is like the following:
If we then have a 3rd collections
db.col3
And compare this one
we'll get the expected result.
If we also have a 4th collection which has matching documents but diffrent data
db.col4
This will also return
false