find.js 963 B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. const OperationBase = require('./operation').OperationBase;
  3. const Aspect = require('./operation').Aspect;
  4. const defineAspects = require('./operation').defineAspects;
  5. const resolveReadPreference = require('../utils').resolveReadPreference;
  6. class FindOperation extends OperationBase {
  7. constructor(collection, ns, command, options) {
  8. super(options);
  9. this.ns = ns;
  10. this.cmd = command;
  11. this.readPreference = resolveReadPreference(collection, this.options);
  12. }
  13. execute(server, callback) {
  14. // copied from `CommandOperationV2`, to be subclassed in the future
  15. this.server = server;
  16. const cursorState = this.cursorState || {};
  17. // TOOD: use `MongoDBNamespace` through and through
  18. server.query(this.ns.toString(), this.cmd, cursorState, this.options, callback);
  19. }
  20. }
  21. defineAspects(FindOperation, [
  22. Aspect.READ_OPERATION,
  23. Aspect.RETRYABLE,
  24. Aspect.EXECUTE_WITH_SELECTION
  25. ]);
  26. module.exports = FindOperation;