我是寻找一种方法来简单地将增量(新对象)添加到生产DB中,同时保留所有其他集合以及同一集合中的旧对象。 到现在为止,我们使用了MySql,所以这个过程只涉及运行DB结构和数据同步(我们使用Navicat)。 我们现在正在迁移到MongoDB,所以这个过程有点棘手。
我已经研究过了,我认为以下解决方案不符合我的需求:
这两种解决方案都是有问题的,因为它们实际上替代了生产数据库所有我想要做的是更新现有集合中的对象。 此外,Dev =>生产不适合主从拓扑。
我想到的最好的事情是:
我想知道任何人都有一个更好的解决方案?
如果没有,有人有脚本可以执行这个吗?
解决方案查看 mongo-sync
这是我为自己写的脚本,当我不断复制我的本地 MongoDB 数据库和从我的一个项目的生产数据库(我知道这是愚蠢的)。
将数据库详细信息放在 config.yml 您可以使用两个简单的命令开始同步:
./ mongo-sync push#Push DB到远程 ./mongo-sync拉#将数据库拉到本地如果你在一些项目中使用它,最好将 config.yml 添加到 .gitignore
We have a dev server which contains a collection of Objects. The actual accumulation of these objects is an ongoing process, which runs a whole process of labelling, verification, etc. on this local dev server. Once these objects, are production ready, they are added to the Production DB, which will from that moment will use them in its calculations.
I'm looking for a way to simply add the delta (new objects) into the production DB, while retaining all the other collections, and older objects in the same collection as is. Until now, we've used MySql, so this process simply involved running DB structure and data synchronization (we used Navicat for that). We're now moving to MongoDB, so this process is a bit more tricky.
I've looked into this, and I think the following solutions do not fit my needs:
Both solutions are problematic, because they actually replace the Production DB, when all I want to do is update objects in an existing collection. Also, going Dev => Production does not fit the Master-Slave topology.
The best thing I could think of is to:
I was wondering if anyone has a better solution?
If not, does anyone have a script that could perform this?
解决方案Check out mongo-sync
It's a script I wrote for my self when I had to constantly copy my Local MongoDB database to and from my Production DB for a Project (I know it's stupid).
Once you put your DB details in config.yml, you can start syncing using two simple commands:
./mongo-sync push # Push DB to Remote ./mongo-sync pull # Pull DB to LocalIf you use it inside some project, it's a good idea to add config.yml to .gitignore
更多推荐
MongoDB同步开发和生产数据库
发布评论