“uncap” a capped MongoDB collection

2019-02-23 21:15发布

问题:

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

thanks

回答1:

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.



回答2:

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


标签: mongodb nosql