something is working

This commit is contained in:
quoije
2022-09-15 01:55:36 -04:00
parent a0aa251c27
commit f38e69883c
1123 changed files with 251731 additions and 11 deletions
+31
View File
@@ -0,0 +1,31 @@
'use strict';
const Server = require('mongodb-topology-manager').Server;
const mongodb = require('mongodb');
run().catch(error => {
console.error(error);
process.exit(-1);
});
async function run() {
// Create new instance
const server = new Server('mongod', {
auth: null,
dbpath: '/data/db/27017'
});
// Purge the directory
await server.purge();
// Start process
await server.start();
const db = await mongodb.MongoClient.connect('mongodb://localhost:27017/admin');
await db.addUser('passwordIsTaco', 'taco', {
roles: ['dbOwner']
});
console.log('done');
}
+35
View File
@@ -0,0 +1,35 @@
'use strict';
run().catch(error => {
console.error(error);
process.exit(-1);
});
async function run() {
const ReplSet = require('mongodb-memory-server').MongoMemoryReplSet;
// Create new instance
const replSet = new ReplSet({
binary: {
version: process.argv[2]
},
instanceOpts: [
// Set the expiry job in MongoDB to run every second
{
port: 27017,
args: ['--setParameter', 'ttlMonitorSleepSecs=1']
}
],
dbName: 'mongoose_test',
replSet: {
name: 'rs0',
count: 2,
storageEngine: 'wiredTiger'
}
});
await replSet.start();
await replSet.waitUntilRunning();
console.log('MongoDB-ReplicaSet is now running.');
console.log(replSet.getUri('mongoose_test'));
}
+46
View File
@@ -0,0 +1,46 @@
'use strict';
run().catch(error => {
console.error(error);
process.exit(-1);
});
async function run() {
const Sharded = require('mongodb-topology-manager').Sharded;
// Create new instance
const topology = new Sharded({
mongod: 'mongod',
mongos: 'mongos'
});
await topology.addShard([{
options: {
bind_ip: 'localhost', port: 31000, dbpath: '/data/db/31000', shardsvr: null
}
}], { replSet: 'rs1' });
await topology.addConfigurationServers([{
options: {
bind_ip: 'localhost', port: 35000, dbpath: '/data/db/35000'
}
}], { replSet: 'rs0' });
await topology.addProxies([{
bind_ip: 'localhost', port: 51000, configdb: 'localhost:35000'
}], {
binary: 'mongos'
});
console.log('Start...');
// Start up topology
await topology.start();
console.log('Started');
// Shard db
await topology.enableSharding('test');
console.log('done');
}