/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. const co = require('co');
  3. co(function*() {
  4. var Sharded = require('mongodb-topology-manager').Sharded;
  5. // Create new instance
  6. var topology = new Sharded({
  7. mongod: 'mongod',
  8. mongos: 'mongos'
  9. });
  10. yield topology.addShard([{
  11. options: {
  12. bind_ip: 'localhost', port: 31000, dbpath: `/data/db/31000`
  13. }
  14. }], { replSet: 'rs1' });
  15. yield topology.addConfigurationServers([{
  16. options: {
  17. bind_ip: 'localhost', port: 35000, dbpath: `/data/db/35000`
  18. }
  19. }], { replSet: 'rs0' });
  20. yield topology.addProxies([{
  21. bind_ip: 'localhost', port: 51000, configdb: 'localhost:35000'
  22. }], {
  23. binary: 'mongos'
  24. });
  25. // Start up topology
  26. yield topology.start();
  27. // Shard db
  28. yield topology.enableSharding('test');
  29. console.log('done');
  30. }).catch(error => {
  31. console.error(error);
  32. process.exit(-1);
  33. });