Skip to content

Mopo is a simple cli tool for replicating MongoDB to PostgreSQL in realtime.

Notifications You must be signed in to change notification settings

rebellionpay/mopo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MOPO

Table of Contents
  1. About
  2. Installation
  3. Configuration
  4. Usage
  5. Attribution

About

Mopo is a simple cli tool for replicating MongoDB to PostgreSQL in realtime.

Installation

git clone https://github.com/rebellionpay/mopo mopo && cd mopo
npm i
npm run build

Preparation

MongoDB

Mopo 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.

PostgreSQL

Launch postgres instance, and create the new database to use.

Configuration

Create a new .mopo.json file like this:

{
    "mongo": {
        "connection": {
            "uri": "<MONGOQUERY>",
            "options": {
                "useNewUrlParser": true,
                "useUnifiedTopology": true,
                "auto_reconnect": true
            }
        },
        "collectionModels": {
            "users": {
                "_id": {
                    "type": "TEXT",
                    "primary": true
                },
                "email": {
                    "type": "TEXT"
                },
                "name": {
                    "type": "TEXT"
                },
                "createdAt": {
                    "type": "TIMESTAMP"
                },
                "updatedAt": {
                    "type": "TIMESTAMP"
                }
            }
        }
    },
    "postgres": {
        "connection": {
            "config": {
                "host": "localhost",
                "database": "exampleDB"
            }
        }
    },
    "sync": [
        {
            "collection": "users",
            "syncAll": true,
            "watchOperations": [
                "INSERT",
                "UPDATE"
            ]
        }
    ]
}

_id field is required for each collection and should be string.

Field names and types

Currently these native types are supported:

  • BIGINT
  • BOOLEAN
  • VARCHAR
  • DATE
  • TIMESTAMP
  • TEXT

Usage

node dist/index.js --start .mopo.json --log-level debug

Usage: index [options]

Options:
  -s, --start <config file>  start sync with config file
  -sa, --sync-all            Sync all data first if schema syncAll enabled
  -bi, --bulk-insert <number>  Number of documents to insert at once (only works if --sync-all enabled). Default 10.
  -l, --log-level <level>    Log level
  -h, --help                 display help for command

Attribution

Icons made by Icongeek26 from www.flaticon.com

About

Mopo is a simple cli tool for replicating MongoDB to PostgreSQL in realtime.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published