Vipul
Vipul

Reputation: 1583

How to convert a MongoDb's capped collection to non-capped collection?

Due to some specific business requirement we were storing data into the MongoDB's capped collection but now complete requirement changed and we want ot preserve all records in that collection.

I am able to find "convertToCapped" command but didn't find any command to perform vise versa operation.

How can I convert it back to non-capped collection?

Upvotes: 3

Views: 2047

Answers (1)

Alex Blex
Alex Blex

Reputation: 37048

You can copy it:

use admin
db.runCommand( { renameCollection: "yourdb.yourcollection", to: "yourdb.oldcapped" } )
use yourdb
db.oldcapped.copyTo("yourcollection")

Then ensure required indexes and create users in uncapped yourcollection. Run your tests, and if you are happy with results, drop oldcapped.

Needless to say it should be done within maintenance window.

Upvotes: 6

Related Questions