如何在不丢失数据的情况下调整mongodb上限的集合的大小? [英] How can I resize a mongodb capped collection without losing data?
问题描述
如何在不丢失数据的情况下调整mongodb上限的集合的大小?
How can I resize a mongodb capped collection without losing data?
是否有相应的命令,或者有人可以提供脚本?
Is there a command for that, or could somebody provide a script?
推荐答案
您基本上需要创建一个新的带帽集合并将文档复制到其中.可以使用javascript(shell)或您选择的语言轻松完成此操作.
You basically need to create a new capped collection and copy the docs to it. This can be done very easily in the javascript (shell), or your language of choice.
db.createCollection("new", {capped:true, size:1073741824}); /* size in bytes */
db.old.find().forEach(function (d) {db.new.insert(d)});
db.old.renameCollection("bak", true);
db.new.renameCollection("old", true);
注意:只需确保切换时没有人在插入/更新旧收藏集.如果您在db.eval("....")中运行该代码,它将在服务器运行时锁定服务器.
Note: Just make sure nobody is inserting/updating the old collection when you switch. If you run that code in a db.eval("....") it will lock the server while it runs.
有一个功能请求,要求增加现有集合的大小: http://jira. mongodb.org/browse/SERVER-1864
There is a feature request for increasing the size of an existing collection: http://jira.mongodb.org/browse/SERVER-1864
这篇关于如何在不丢失数据的情况下调整mongodb上限的集合的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!