重命名MongoDB集合时,索引是否完整?
执行此操作时,索引是否保持不变重命名MongoDB集合时,索引是否完整?,mongodb,Mongodb,执行此操作时,索引是否保持不变 db.collection('my-collection').rename('new-collection-name', {dropTarget:true}); 使用mongo cli,可以轻松测试: $ mongo > db.bob.ensureIndex({ name: 1 }) { "createdCollectionAutomatically" : true, "numIndexesBefore" : 1, "numInde
db.collection('my-collection').rename('new-collection-name', {dropTarget:true});
使用mongo cli,可以轻松测试:
$ mongo
> db.bob.ensureIndex({ name: 1 })
{
"createdCollectionAutomatically" : true,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
> db.bob.renameCollection('robert', { dropTarget: true })
{ "ok" : 1 }
> db.robert.getIndices()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "test.robert"
},
{
"v" : 1,
"key" : {
"name" : 1
},
"name" : "name_1",
"ns" : "test.robert"
}
]
因此,是的,看起来指数确实保持不变。不确定,可能不确定。但通过实验很容易发现,不是吗?