执行此操作时,指数会保持不变吗?
db.collection('my-collection').rename('new-collection-name', {dropTarget:true});
答案 0 :(得分:1)
使用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"
}
]
所以,是的,看起来指数确实保持不变。