https://github.com/cuchi/mongo-reporting-replica
Using MongoDB replica sets feature to setup an reporting instance
https://github.com/cuchi/mongo-reporting-replica
Last synced: 2 months ago
JSON representation
Using MongoDB replica sets feature to setup an reporting instance
- Host: GitHub
- URL: https://github.com/cuchi/mongo-reporting-replica
- Owner: cuchi
- Created: 2018-03-01T19:21:04.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-01T19:21:14.000Z (over 8 years ago)
- Last Synced: 2025-03-23T05:24:13.447Z (over 1 year ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
This repository shows the usage of the Replica Set feature from MongoDB to serve
what we can call a *reporting replica*.
As the name says, the main purpose of this kind of replica is not to ensure
high availability, but to provide an easy way to get an real-time copy of the
production database. This replica can be queried without any performance impact
on the production evironment.
## Running this example
You will need `docker`, `docker-compose` and a local `mongo` client to get this
example working.
First, start both of the mongodb instances:
```bash
docker-compose up -d mongo mongo-replica
```
Then, log in the first instance, we will choose this one to be our *primary*
replica.
```bash
mongo localhost:10001
```
Initialize the replica set, then add the secondary instance:
```javascript
rs.initiate()
rs.add({ host: 'mongo-replica:27017', hidden: true, priority: 0 })
```
Get the worker up and running:
```bash
docker-compose up -d worker
```
You should be able to see the data being replicated from `localhost:10001` to
`localhost:10002`.
## What is missing?
- For the sake of simplicity, there is no authentication setup in this example.
This is something I will add later.