MongoDB同步开发和生产数据库 [英] MongoDB synchronize Development and Production databases

查看:161
本文介绍了MongoDB同步开发和生产数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个包含对象集合的开发服务器。
这些对象的实际累积是一个持续的过程,它在本地的dev服务器上运行一个标签,验证等的整个过程。
一旦这些对象生产准备就绪,它们就被添加到生产数据库中,从那时起将使用它们进行计算。



我是寻找一种方法来简单地将增量(新对象)添加到生产DB中,同时保留所有其他集合以及同一集合中的旧对象。
到现在为止,我们使用了MySql,所以这个过程只涉及运行DB结构和数据同步(我们使用Navicat)。
我们现在正在迁移到MongoDB,所以这个过程有点棘手。



我已经研究过了,我认为以下解决方案不符合我的需求:


  1. 转载开发数据库,​​并使用 mongodump then mongorestore

  2. 运行db.copyDatabase - 实际上用制造数据库的副本替换了生产数据库。

这两种解决方案都是有问题的,因为它们实际上替代了生产数据库所有我想要做的是更新现有集合中的对象。
此外,Dev =>生产不适合主从拓扑。



我想到的最好的事情是:


  1. 将开发数据库复制到生产实例上的dev数据库。

  2. 从该开发数据库复制集合到实际的生产DB,并添加一个谓词,我将只添加在生产DB中不存在的对象,类似于这个解决方案

我想知道任何人都有一个更好的解决方案?



如果没有,有人有脚本可以执行这个吗?

解决方案

查看 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:

  1. Dumping the dev DB and loading it in the Production DB using mongodump then mongorestore
  2. Running db.copyDatabase - actually replaces the production db with a copy of the dev DB.

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:

  1. Copy the dev DB into a "dev" DB on the production instance.
  2. Copy the collection from this dev DB to the actual production DB, and add a predicate that I will only add objects that are non-existent in the production DB, similar to this solution.

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 Local

If you use it inside some project, it's a good idea to add config.yml to .gitignore


这篇关于MongoDB同步开发和生产数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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