如何在不丢失数据的情况下调整 mongodb 上限集合的大小? [英] How can I resize a mongodb capped collection without losing data?

查看:11
本文介绍了如何在不丢失数据的情况下调整 mongodb 上限集合的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不丢失数据的情况下调整 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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆