repl.js 762 B

1234567891011121314151617181920212223242526272829303132333435
  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. ],
  20. dbName: 'mongoose_test',
  21. replSet: {
  22. name: 'rs0',
  23. count: 2,
  24. storageEngine: 'wiredTiger'
  25. }
  26. });
  27. await replSet.start();
  28. await replSet.waitUntilRunning();
  29. console.log('MongoDB-ReplicaSet is now running.');
  30. console.log(replSet.getUri('mongoose_test'));
  31. }