Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"uncap" a capped MongoDB collection

Tags:

mongodb

nosql

is there a way to "uncap" a capped collection? Creating a new collection and copy the data isn't an option for me.

thanks

like image 862
Backlit Avatar asked Jan 11 '12 08:01

Backlit


People also ask

How do I update a capped collection in MongoDB?

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.

How do I remove documents from capped collection in MongoDB?

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.

What is a capped collection in MongoDB?

What Is a Capped Collection in MongoDB? Fixed-size collections are called capped collections in MongoDB. While creating a collection, the user must specify the collection's maximum size in bytes and the maximum number of documents that it would store.

How do I replicate a collection in MongoDB?

Right-click on collection1 collection in DB Explorer and select Duplicate 'collection1' Collection... item in the popup menu. Specify destination collection name, duplication parameters and click Duplicate.


2 Answers

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.

like image 198
Remon van Vliet Avatar answered Sep 27 '22 18:09

Remon van Vliet


Unfortunately, the only option here is to copy collection, remove the old one and rename the new one:

$> db.collection_name.copyTo('collection_name2')
$> db.collection_name.isCapped()
true
$> db.collection_name.drop()
$> db.collection_name2.renameCollection('collection_name')
$> db.collection_name.isCapped()
false
like image 39
mieciu Avatar answered Sep 27 '22 18:09

mieciu