UNPKG

931 BJavaScriptView Raw
1'use strict';
2
3const co = require('co');
4
5co(function*() {
6 var Sharded = require('mongodb-topology-manager').Sharded;
7
8 // Create new instance
9 var topology = new Sharded({
10 mongod: 'mongod',
11 mongos: 'mongos'
12 });
13
14 yield topology.addShard([{
15 options: {
16 bind_ip: 'localhost', port: 31000, dbpath: `/data/db/31000`, shardsvr: null
17 }
18 }], { replSet: 'rs1' });
19
20 yield topology.addConfigurationServers([{
21 options: {
22 bind_ip: 'localhost', port: 35000, dbpath: `/data/db/35000`
23 }
24 }], { replSet: 'rs0' });
25
26 yield topology.addProxies([{
27 bind_ip: 'localhost', port: 51000, configdb: 'localhost:35000'
28 }], {
29 binary: 'mongos'
30 });
31
32 console.log('Start...');
33 // Start up topology
34 yield topology.start();
35
36 console.log('Started');
37
38 // Shard db
39 yield topology.enableSharding('test');
40
41 console.log('done');
42}).catch(error => {
43 console.error(error);
44 process.exit(-1);
45});