Mongodb – Moving a collection to a new database (v2.2)

concurrencymongodb

To take advantage of the improved concurrency in Mongodb 2.2–namely database level locking–we would like to move a sharded collection to a new database.

I have been unable to find any documentation which will help with this particular scenario.

I know I cant just "rename" this sharded collection: https://groups.google.com/d/topic/mongodb-user/lajAcp3HkZ4/discussion

The only thing I can think of is mongodump the entire collection and mongorestore into a new database. What are my other options?

Best Answer

A mongodump and mongorestore (or a similar script to accomplish the same thing) to backup and re-import the data is the most straight forward way of doing this at the moment until SERVER-6063 is implemented.

The only other option I can think of would be to move all chunks to a single shard, wipe out the sharding config for the collection (effectively unsharding it) and then do the rename on that shard. Once that was complete, you could re-shard the collection.

This would be:

  1. Dangerous (messing with the config meta data is always a bad idea)
  2. Unsupported (if you get into trouble, it's probably up to you to fix it)
  3. More complicated (since the first recommended thing to do would be to backup your data via mongodump)

As one other alternative - can you move everything else (perhaps unsharded) out of this database? Obviously this would not be helpful if you have other large sharded collections in this DB, but just wanted to make sure it was considered.