remove_user.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. 'use strict';
  2. const Aspect = require('./operation').Aspect;
  3. const CommandOperation = require('./command');
  4. const defineAspects = require('./operation').defineAspects;
  5. const handleCallback = require('../utils').handleCallback;
  6. const WriteConcern = require('../write_concern');
  7. class RemoveUserOperation extends CommandOperation {
  8. constructor(db, username, options) {
  9. const commandOptions = {};
  10. const writeConcern = WriteConcern.fromOptions(options);
  11. if (writeConcern != null) {
  12. commandOptions.writeConcern = writeConcern;
  13. }
  14. if (options.dbName) {
  15. commandOptions.dbName = options.dbName;
  16. }
  17. // Add maxTimeMS to options if set
  18. if (typeof options.maxTimeMS === 'number') {
  19. commandOptions.maxTimeMS = options.maxTimeMS;
  20. }
  21. super(db, commandOptions);
  22. this.username = username;
  23. }
  24. _buildCommand() {
  25. const username = this.username;
  26. // Build the command to execute
  27. const command = { dropUser: username };
  28. return command;
  29. }
  30. execute(callback) {
  31. // Attempt to execute command
  32. super.execute((err, result) => {
  33. if (err) return handleCallback(callback, err, null);
  34. handleCallback(callback, err, result.ok ? true : false);
  35. });
  36. }
  37. }
  38. defineAspects(RemoveUserOperation, Aspect.WRITE_OPERATION);
  39. module.exports = RemoveUserOperation;