#创建新的集合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 }
> 

 

相关文章:

  • 2021-11-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-24
  • 2021-12-09
  • 2021-05-27
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-29
  • 2022-12-23
  • 2021-09-17
  • 2022-12-23
相关资源
相似解决方案