如何在MongoDB中重命名集合?
要在MongoDB中重命名集合,可以使用renameCollection()方法。语法如下-
db.yourOldCollectionName.renameCollection('yourNewCollectionName');为了理解上述语法,让我们列出数据库样本中的所有集合。查询如下-
> use sample; switched to db sample > show collections;
以下是输出-
copyThisCollectionToSampleDatabaseDemo deleteDocuments deleteDocumentsDemo employee informationAboutDelete internalArraySizeDemo prettyDemo selectWhereInDemo sourceCollection updateInformation userInformation
现在,将集合名称“informationAboutDelete”更改为“deleteSomeInformation”。查询如下以更改集合名称。
> db.informationAboutDelete.renameCollection('deleteSomeInformation');
{ "ok" : 1 }这是查询以检查集合名称已重命名为'deleteSomeInformation'-
> show collections;
以下是输出-
copyThisCollectionToSampleDatabaseDemo deleteDocuments deleteDocumentsDemo deleteSomeInformation employee internalArraySizeDemo prettyDemo selectWhereInDemo sourceCollection updateInformation userInformation
热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿