PageRenderTime 31ms CodeModel.GetById 21ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/node_modules/mongoose/tools/sharded.js

https://bitbucket.org/coleman333/smartsite
JavaScript | 42 lines | 30 code | 9 blank | 3 comment | 0 complexity | d3318730f64f448bc9c6a6a2eae33005 MD5 | raw file
 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`
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  // Start up topology
33  yield topology.start();
34
35  // Shard db
36  yield topology.enableSharding('test');
37
38  console.log('done');
39}).catch(error => {
40  console.error(error);
41  process.exit(-1);
42});