auth.js 602 B

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. const Server = require('mongodb-topology-manager').Server;
  3. const mongodb = require('mongodb');
  4. run().catch(error => {
  5. console.error(error);
  6. process.exit(-1);
  7. });
  8. async function run() {
  9. // Create new instance
  10. const server = new Server('mongod', {
  11. auth: null,
  12. dbpath: '/data/db/27017'
  13. });
  14. // Purge the directory
  15. await server.purge();
  16. // Start process
  17. await server.start();
  18. const db = await mongodb.MongoClient.connect('mongodb://localhost:27017/admin');
  19. await db.addUser('passwordIsTaco', 'taco', {
  20. roles: ['dbOwner']
  21. });
  22. console.log('done');
  23. }