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?
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.
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.
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.
Capped collections are fixed-size circular collections that follow the insertion order to support high performance for create, read, and delete operations.
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);}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With