| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
9年前发布

实时将MongoDB数据复制至MySQL中:Momy

Momy 是一个简单的cli工具用于实时将MongoDB数据复制至MySQL中。

  • 实现在NoSQL数据库进行SQL查询
  • 实现通过Excel / Access访问

Momy

安装

$ npm install -g momy

or install it within the project locally:

$ npm install --save momy

准备

MongoDB

Momy uses Replica Set feature in MongoDB. But you don't have to replicate between MongoDB actually. Just follow the steps below.

Start a new mongo instance with no data:

$ mongod --replSet "rs0" --oplogSize 100

Open another terminal, and go to MongoDB Shell:

$ mongo  .... > rs.initiate()

rs.initiate()command prepare the collections that is needed for replication.

MySQL

Launch MySQL instance, and create the new database to use. The tables will be created or updated when syncing. You'll seemongo_to_mysql, too. This is needed to store the information for syncing. (don't remove it)

配置

Create a newmomyfile.jsonfile like this:

{    "src": "mongodb://localhost:27017/dbname",    "dist": "mysql://root@localhost:3306/dbname",    "prefix": "t_",    "collections": {      "collection1": {        "_id": "number",        "field1": "number",        "field2": "string",        "field3": "boolean"      },      "collection2": {        "_id": "number",        "field1": "number",        "field2": "string",        "field3": "boolean"      }    }  }

  • src: the URL of the MongoDB server
  • dist: the URL of the MySQL server
  • prefix: optional prefix for table name. The name of the table would bet_collection1in the example above.
  • collections: set the collections and fields to sync

用法

At the first run, we need to import all the data from MongoDB:

$ momy --config momyfile.json --import

Then start the daemon to streaming data:

$ momy --config momyfile.json

or

$ forever momy --config momyfile.json

项目主页:http://www.open-open.com/lib/view/home/1445519642085

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1445519642085.html
Momy MongoDB NoSQL数据库