9

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

thanks

Community
  • 1
  • 1
Backlit
  • 341
  • 1
  • 5
  • 13

2 Answers2

9

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.

Remon van Vliet
  • 18,365
  • 3
  • 52
  • 57
  • Thank you so much for your answer. Is "clone" a MongoDB function, or is that just the general idea of what you'd need to do? – john_science Apr 01 '12 at 21:43
7

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
Kristofersen
  • 2,736
  • 1
  • 15
  • 31
mieciu
  • 448
  • 3
  • 7
  • 3
    DON'T DO THIS. `copyTo` takes a global lock and will block all write operations. If you do it in production, it will take everything down. Instead see https://stackoverflow.com/questions/10624964/whats-the-fastest-way-to-copy-a-collection-within-the-same-database#33889197 – lbolla Sep 24 '18 at 10:10