repl.js 760 B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. run().catch(error => {
  3. console.error(error);
  4. process.exit(-1);
  5. });
  6. async function run () {
  7. const ReplSet = require('mongodb-memory-server').MongoMemoryReplSet;
  8. // Create new instance
  9. const replSet = new ReplSet({
  10. binary: {
  11. version: process.argv[2]
  12. },
  13. instanceOpts: [
  14. // Set the expiry job in MongoDB to run every second
  15. {
  16. port: 27017,
  17. args: ["--setParameter", "ttlMonitorSleepSecs=1"] },
  18. ],
  19. dbName: 'mongoose_test',
  20. replSet: {
  21. name: "rs0",
  22. count: 2,
  23. storageEngine: "wiredTiger",
  24. },
  25. });
  26. await replSet.start();
  27. await replSet.waitUntilRunning();
  28. console.log("MongoDB-ReplicaSet is now running.")
  29. console.log(replSet.getUri("mongoose_test"));
  30. }