Skip to content

Instantly share code, notes, and snippets.

@si294r
Created December 21, 2017 04:54
Show Gist options
  • Select an option

  • Save si294r/8dfa7bd6aa66c3b5b4d98220f7a8a760 to your computer and use it in GitHub Desktop.

Select an option

Save si294r/8dfa7bd6aa66c3b5b4d98220f7a8a760 to your computer and use it in GitHub Desktop.

Install mongodb :

Development

file mongo.conf

storage: dbPath: /data/db directoryPerDB: true journal: enabled: true engine: wiredTiger

wiredTiger: engineConfig: cacheSizeGB: 2

net: port: 27017 bindIp: 0.0.0.0

security: authorization: enabled

Docker

docker run --name mongodb -v /root/database/mongodb:/data/db -p 27017:27017 -d mongo -f /data/db/mongod.conf

Production

file mongo.conf

storage: dbPath: /data/db directoryPerDB: true journal: enabled: true engine: wiredTiger

wiredTiger: engineConfig: cacheSizeGB: 4

net: port: 27017 bindIp: 0.0.0.0

security: authorization: enabled keyFile: /data/db/replication_keyfile

replication: replSetName: replicaName

Docker

docker run --name mongodb_prod -v /root/database/mongodb_prod:/data/db -p 51017:27017 -d mongo -f /data/db/mongod.conf

rs.initiate() rs.reconfig({ _id: "replicaName", members: [{ _id: 0, host: "198.58.109.95:51017"}] }) rs.add('45.33.112.188:51017') rs.status() use admin db.createUser({ user: 'admin', pwd: 'password', roles: [{ role: 'userAdminAnyDatabase', db: 'admin' }] }) db.createUser({ user: 'rootAdmin', pwd: 'password', roles: [{ role: 'root', db: 'admin' }] })

openssl rand -base64 756 > database/mongodb_prod/replication_keyfile chmod 400 database/mongodb_prod/replication_keyfile scp database/mongodb_prod/replication_keyfile [email protected]:~/database/mongodb_prod

mongo -u admin -p password admin use billionaire db.createUser({ user: 'user', pwd: 'password', roles: [{ role: 'dbOwner', db: 'billionaire' }] }) db.grantRolesToUser("user", [{ role: "readAnyDatabase", db: "admin" }]);

Dump

mongodump -u user -p password -d billionaire -o /data/db/backup_$(date +%Y%m%d%H) --host=iad1-c13-1.mongo.objectrocket.com --port=51017

2017-12-19T08:21:05.528+0000 2017-12-19T08:29:57.682+0000

Restore

mongorestore -u user -p password --authenticationDatabase billionaire --drop /data/db/backup_2017121903/

2017-12-19T04:09:32.493+0000 2017-12-19T04:42:27.022+0000

2017-12-19T08:32:15.286+0000 2017-12-19T09:05:02.093+0000

"PARSE_SERVER_DATABASE_URI": "mongodb://user:[email protected]:51017/billionaire",

Dump mongodb :

mongodump -u user -p password -d billionaire -o /data/db/backup_$(date +%Y%m%d%H) --host=iad1-c13-1.mongo.objectrocket.com --port=51017

2017-12-07T10:46:24.189+0000 2017-12-07T10:59:13.339+0000

2017-12-12T08:14:30.792+0000 2017-12-12T08:18:39.078+0000

Restore mongodb :

mongorestore --drop /data/db/backup_2017120710/

Cache Size: 2GB - 40 minute 2017-12-07T12:49:08.546+0000 2017-12-07T13:29:32.376+0000

Default Cache Size: 3GB - 33 minute 2017-12-08T04:00:25.911+0000 2017-12-08T04:33:42.541+0000

Cache Size: 4GB - 30 minute 2017-12-08T08:47:58.829+0000 2017-12-08T09:17:54.259+0000

Test Query Leaderboard

alegrium2.alegrium.com/parse/functions/globalLeaderboardRank_iOS = 11.690 ms

api.alegrium.com/parse_prod/functions/globalLeaderboardRankOld_iOS = 20.361 ms

Object Rocket Connect

parse-server --appId APPLICATION_ID --masterKey MASTER_KEY --databaseURI mongodb://YOUR_USERNAME:[email protected]:51017,iad1-c13-1.mongo.objectrocket.com:51017,iad1-c13-2.mongo.objectrocket.com:51017/YOUR_DATABASE_NAME?replicaSet=436390de1a0f4590b67ecf7052254da8

"PARSE_SERVER_DATABASE_URI": "mongodb://user:[email protected]:51017,45.33.112.188:51017/billionaire?replicaSet=replicaName&readPreference=secondaryPreferred"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment