UNPKG

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