/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
- 'use strict';
- const co = require('co');
- co(function*() {
- var Sharded = require('mongodb-topology-manager').Sharded;
- // Create new instance
- var topology = new Sharded({
- mongod: 'mongod',
- mongos: 'mongos'
- });
- yield topology.addShard([{
- options: {
- bind_ip: 'localhost', port: 31000, dbpath: `/data/db/31000`
- }
- }], { replSet: 'rs1' });
- yield topology.addConfigurationServers([{
- options: {
- bind_ip: 'localhost', port: 35000, dbpath: `/data/db/35000`
- }
- }], { replSet: 'rs0' });
- yield topology.addProxies([{
- bind_ip: 'localhost', port: 51000, configdb: 'localhost:35000'
- }], {
- binary: 'mongos'
- });
- // Start up topology
- yield topology.start();
- // Shard db
- yield topology.enableSharding('test');
- console.log('done');
- }).catch(error => {
- console.error(error);
- process.exit(-1);
- });