Add renameCollection command
Closed this issue ยท 7 comments
> db.adminCommand( { renameCollection: "vishaltest.stores", to : "vishaltest.stores123"})
{
"errmsg" : "no such cmd: renamecollection",
"bad cmd" : "{ renameCollection: "vishaltest.stores", to: "vishaltest.stores123" }",
"ok" : 0
}
> use vishaltest
switched to db vishaltest
> db.stores.renameCollection("stores1234")
{
"errmsg" : "no such cmd: renamecollection",
"bad cmd" : "{ renameCollection: "vishaltest.stores", to: "vishaltest.stores1234", dropTarget: false }",
"ok" : 0
}
>
@apkar We like to take up this ticket. The proposed solution is,
- Register new command for Rename
- Validate the collection name for existence
- Use MOVE function to create and update the directory path
- Add internal_doDropIndexesActor function to update system.indexes
Please assign it to me, if this is ok.
@senthil-db-expert Why do you need to drop the indexes ?
If we take a simple case with a collection and index like below
db = client['test']
db.coll.create_index('field_a')
db.coll.insert_one({'field_a': 'value_a_1', '_id': 'Bhaskar'})
Assuming it creates directory structure like below
โ
โโโ Status Monitor -> \x15\x35
โ โโโ Layers -> \x15\x08
โโโ document -> \x15\x1c
โโโ test -> \x15\x1d
โโโ coll -> \x15\x07
โ โโโ metadata -> \x15\x2c
โโโ system.indexes -> \x15\x16
โโโ metadata -> \x15\x31
We will have primary index
`\x15\x07(Bhaskar\x00' is `2'
`\x15\x07(Bhaskar\x00(_id\x00' is `(Bhaskar'
`\x15\x07(Bhaskar\x00(field_a\x00' is `(value_a_1'
And secondary index
`\x15\x2c(indices\x00(field_a\x00(value_a_1\x00(Bhaskar\x00' is `'
We don't have to rewrite any of the primary/secondary index keys. We will need to rename (or move) the directory path and change the entry in system.indexes
to point to new namespace. And it should bump the metadata version for the collection.
Agree @apkar Thanks. Will work on it and raise the PR.
@apkar the fix is ready. We will be raising PR today under account drkannan
@apkar any reason why this issue still in open state? Like to understand the process.
Usually, if a single PR is closing an issue, we go with the following keywords which would automatically close the issue.
https://help.github.com/en/articles/closing-issues-using-keywords
Also, it's just me being lazy.