mongodb - 集合重命名


#創建新的集合yb
> for(i=0;i<10;i++){db.yb.insert({'i':i})}
WriteResult({ "nInserted" : 1 })
> show collections
yb
#重命名集合為yb2
> db.yb.renameCollection('yb2');
{ "ok" : 1 }
> show collections
yb2
> 

 

跨數據庫重名集合

> use test
switched to db test
> show collections
yb1
> use test2
switched to db test2
> show collections
> db.runCommand({renameCollection:"test.yb1",to:"test2.yb",dropTarget:true});
{
        "ok" : 0,
        "errmsg" : "renameCollection may only be run against the admin database.",
        "code" : 13
}
> show collections
> use admin
switched to db admin
> db.runCommand({renameCollection:"test.yb1",to:"test2.yb",dropTarget:true});
{ "ok" : 1 }
> 

 


免責聲明!

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



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