Mongodb Clone Local collection
Mongodb does not provide a way to copy collections locally, so you can write a circular insert method to complete mongodb local cloning of a collection data:
Db.source_collection.find () .forEach (function (x) {db.target_collection.insert (x)})
For example, clone all the data in the collection:
Db.userinfo.find () .forEach (function (x) {db.userinfo_bak.insert (x)})
Filter the data of the clone collection:
Repset:PRIMARY > db.user.count ()
850940
Repset:PRIMARY > db.user.count ({iVO 100})
one
Repset:PRIMARY > db.userinfo.find ({iVl100}) .forEach (function (x) {db.user_bak.insert (x)})
Repset:PRIMARY > db.user_bak.count ({iVO 100})
one