kill_cursors.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.KillCursorsOperation = void 0;
  4. const error_1 = require("../error");
  5. const operation_1 = require("./operation");
  6. class KillCursorsOperation extends operation_1.AbstractOperation {
  7. constructor(cursorId, ns, server, options) {
  8. super(options);
  9. this.ns = ns;
  10. this.cursorId = cursorId;
  11. this.server = server;
  12. }
  13. async execute(server, session) {
  14. if (server !== this.server) {
  15. throw new error_1.MongoRuntimeError('Killcursor must run on the same server operation began on');
  16. }
  17. const killCursors = this.ns.collection;
  18. if (killCursors == null) {
  19. // Cursors should have adopted the namespace returned by MongoDB
  20. // which should always defined a collection name (even a pseudo one, ex. db.aggregate())
  21. throw new error_1.MongoRuntimeError('A collection name must be determined before killCursors');
  22. }
  23. const killCursorsCommand = {
  24. killCursors,
  25. cursors: [this.cursorId]
  26. };
  27. try {
  28. await server.commandAsync(this.ns, killCursorsCommand, { session });
  29. }
  30. catch {
  31. // The driver should never emit errors from killCursors, this is spec-ed behavior
  32. }
  33. }
  34. }
  35. exports.KillCursorsOperation = KillCursorsOperation;
  36. (0, operation_1.defineAspects)(KillCursorsOperation, [operation_1.Aspect.MUST_SELECT_SAME_SERVER]);
  37. //# sourceMappingURL=kill_cursors.js.map