Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add renameCollection command #94

Closed
apkar opened this issue Feb 23, 2019 · 7 comments
Closed

Add renameCollection command #94

apkar opened this issue Feb 23, 2019 · 7 comments
Assignees
Milestone

Comments

@apkar
Copy link
Contributor

apkar commented Feb 23, 2019

> 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 apkar added this to the 1.7.0 milestone Mar 25, 2019
@apkar apkar modified the milestones: 1.7.0, 1.8.0 Apr 1, 2019
@senthil-db-expert
Copy link

@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.

@apkar
Copy link
Contributor Author

apkar commented Jul 9, 2019

@senthil-db-expert Why do you need to drop the indexes ?

@apkar
Copy link
Contributor Author

apkar commented Jul 9, 2019

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.

@senthil-db-expert
Copy link

Agree @apkar Thanks. Will work on it and raise the PR.

@senthil-db-expert
Copy link

@apkar the fix is ready. We will be raising PR today under account drkannan

apkar added a commit that referenced this issue Aug 1, 2019
Resolves issue #94: Add  renameCollection command
@senthil-db-expert
Copy link

@apkar any reason why this issue still in open state? Like to understand the process.

@apkar
Copy link
Contributor Author

apkar commented Aug 8, 2019

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.

@apkar apkar closed this as completed Aug 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants