Get the App
SLTechnology News&Howtos  ›  Database  › 

Mongodb Clone Local collection

Shulou Source: shulou.com Published: 2022-06-01 22:33:17 10月20日 Update

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

Tags: Data methods loops Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL vpn macOS OPPO Reno Huawei