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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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);}
回答2:
same as above without using script.
db.collection.copyTo("collection_temp")
db.collection.drop()
db.collection_temp.renameCollection("collection")
回答3:
I think there is a way! I'm not sure if this is bullet-proof, but I tried:
db.num_coll.convertToCapped(new_size)
and since then it is working.