分类目录归档:mongodb

resize a mongodb capped collection 重新设置mongo固定表的大小

最近公司需要将一个旧的capped collection重新调整大小最后在google大神的指导下成功找到解决方案。记录一下。
道理很简单,相信略懂mongo的程序猿都能看懂。

db.createCollection("new", {capped:true, size:1073741824}); 
db.old.find().forEach(function (d) {db.new.insert(d)});
db.old.renameCollection("bak", true);
db.new.renameCollection("old", true);