Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undo convertToCapped to a collection

Tags:

mongodb

nosql

In MongoDB you can convert a collection into a capped collection with the command convertToCapped, but is there a way to revert this change so a capped collection goes back to normal?

like image 800
Abel Tamayo Avatar asked Oct 19 '10 18:10

Abel Tamayo


People also ask

How do I uncap a collection in MongoDB?

No, You can convert a non-capped collection to a capped collection using the "convertToCapped" command but there's no way to go the other way. Your only option is to clone the collection to a non capped one and rename it which obviously involves downtime.

Can not remove from a capped collection?

You cannot delete documents from a capped collection. It can only be deleted automatically upon insertion of new documents when the allocated size to the collection has been exhausted. After reading the documents from a capped collection, MongoDB returns the same document in the order which they were present on disk.

How do you turn a collection into a capped collection?

Convert a Collection to Capped You can convert a non-capped collection to a capped collection with the convertToCapped command: db. runCommand({"convertToCapped": "mycoll", size: 100000}); The size parameter specifies the size of the capped collection in bytes.

What is a capped collection?

Capped collections are fixed-size circular collections that follow the insertion order to support high performance for create, read, and delete operations.


1 Answers

It's seems there is only one way to convert from capped collection to normal - just simple copy objects to normal collection and remove original capped collection.


db.createCollection("norm_coll");
var cur = db.cap_col.find()
while (cur.hasNext()) {obj = cur.next(); db.norm_coll.insert(obj);}

like image 125
walla Avatar answered Oct 04 '22 03:10

walla