execute_db_admin_command.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. const OperationBase = require('./operation').OperationBase;
  3. const handleCallback = require('../utils').handleCallback;
  4. const MongoError = require('../core').MongoError;
  5. const MongoDBNamespace = require('../utils').MongoDBNamespace;
  6. class ExecuteDbAdminCommandOperation extends OperationBase {
  7. constructor(db, selector, options) {
  8. super(options);
  9. this.db = db;
  10. this.selector = selector;
  11. }
  12. execute(callback) {
  13. const db = this.db;
  14. const selector = this.selector;
  15. const options = this.options;
  16. const namespace = new MongoDBNamespace('admin', '$cmd');
  17. db.s.topology.command(namespace, selector, options, (err, result) => {
  18. // Did the user destroy the topology
  19. if (db.serverConfig && db.serverConfig.isDestroyed()) {
  20. return callback(new MongoError('topology was destroyed'));
  21. }
  22. if (err) return handleCallback(callback, err);
  23. handleCallback(callback, null, result.result);
  24. });
  25. }
  26. }
  27. module.exports = ExecuteDbAdminCommandOperation;