mongodb重命名集合、數據庫


重命名集合

mongoshell里就可以實現

db.orders.renameCollection( "orders2014" )

通過cmd:renameCollection重命名數據庫

沒有直接的接口,直接copydb數據很多時比較費時間,不過可以通過

{ renameCollection: "<source_namespace>", to: "<target_namespace>", dropTarget: <true|false> }

dropTarget boolean 是否在集合同名時刪除原集合,默認為true
該操作會阻塞所有數據庫操作
例子

db.runCommand( { renameCollection: "test.orders", to: "test.orders2014" }

如果要重命名數據庫,使用js做一個循環的函數便搞定


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM