list_databases.js 992 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. const CommandOperationV2 = require('./command_v2');
  3. const Aspect = require('./operation').Aspect;
  4. const defineAspects = require('./operation').defineAspects;
  5. const MongoDBNamespace = require('../utils').MongoDBNamespace;
  6. class ListDatabasesOperation extends CommandOperationV2 {
  7. constructor(db, options) {
  8. super(db, options);
  9. this.ns = new MongoDBNamespace('admin', '$cmd');
  10. }
  11. execute(server, callback) {
  12. const cmd = { listDatabases: 1 };
  13. if (this.options.nameOnly) {
  14. cmd.nameOnly = Number(cmd.nameOnly);
  15. }
  16. if (this.options.filter) {
  17. cmd.filter = this.options.filter;
  18. }
  19. if (typeof this.options.authorizedDatabases === 'boolean') {
  20. cmd.authorizedDatabases = this.options.authorizedDatabases;
  21. }
  22. super.executeCommand(server, cmd, callback);
  23. }
  24. }
  25. defineAspects(ListDatabasesOperation, [
  26. Aspect.READ_OPERATION,
  27. Aspect.RETRYABLE,
  28. Aspect.EXECUTE_WITH_SELECTION
  29. ]);
  30. module.exports = ListDatabasesOperation;