get_more.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.GetMoreOperation = void 0;
  4. const responses_1 = require("../cmap/wire_protocol/responses");
  5. const error_1 = require("../error");
  6. const utils_1 = require("../utils");
  7. const operation_1 = require("./operation");
  8. /** @internal */
  9. class GetMoreOperation extends operation_1.AbstractOperation {
  10. constructor(ns, cursorId, server, options) {
  11. super(options);
  12. this.SERVER_COMMAND_RESPONSE_TYPE = responses_1.CursorResponse;
  13. this.options = options;
  14. this.ns = ns;
  15. this.cursorId = cursorId;
  16. this.server = server;
  17. }
  18. get commandName() {
  19. return 'getMore';
  20. }
  21. buildCommand(connection) {
  22. if (this.cursorId == null || this.cursorId.isZero()) {
  23. throw new error_1.MongoRuntimeError('Unable to iterate cursor with no id');
  24. }
  25. const collection = this.ns.collection;
  26. if (collection == null) {
  27. // Cursors should have adopted the namespace returned by MongoDB
  28. // which should always defined a collection name (even a pseudo one, ex. db.aggregate())
  29. throw new error_1.MongoRuntimeError('A collection name must be determined before getMore');
  30. }
  31. const getMoreCmd = {
  32. getMore: this.cursorId,
  33. collection
  34. };
  35. if (typeof this.options.batchSize === 'number') {
  36. getMoreCmd.batchSize = Math.abs(this.options.batchSize);
  37. }
  38. if (typeof this.options.maxAwaitTimeMS === 'number') {
  39. getMoreCmd.maxTimeMS = this.options.maxAwaitTimeMS;
  40. }
  41. // we check for undefined specifically here to allow falsy values
  42. // eslint-disable-next-line no-restricted-syntax
  43. if (this.options.comment !== undefined && (0, utils_1.maxWireVersion)(connection) >= 9) {
  44. getMoreCmd.comment = this.options.comment;
  45. }
  46. return getMoreCmd;
  47. }
  48. buildOptions(timeoutContext) {
  49. return {
  50. returnFieldSelector: null,
  51. documentsReturnedIn: 'nextBatch',
  52. timeoutContext,
  53. ...this.options
  54. };
  55. }
  56. handleOk(response) {
  57. return response;
  58. }
  59. }
  60. exports.GetMoreOperation = GetMoreOperation;
  61. (0, operation_1.defineAspects)(GetMoreOperation, [operation_1.Aspect.READ_OPERATION, operation_1.Aspect.MUST_SELECT_SAME_SERVER]);
  62. //# sourceMappingURL=get_more.js.map