estimated_document_count.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.EstimatedDocumentCountOperation = void 0;
  4. const responses_1 = require("../cmap/wire_protocol/responses");
  5. const command_1 = require("./command");
  6. const operation_1 = require("./operation");
  7. /** @internal */
  8. class EstimatedDocumentCountOperation extends command_1.CommandOperation {
  9. constructor(collection, options = {}) {
  10. super(collection, options);
  11. this.SERVER_COMMAND_RESPONSE_TYPE = responses_1.MongoDBResponse;
  12. this.options = options;
  13. this.collectionName = collection.collectionName;
  14. }
  15. get commandName() {
  16. return 'count';
  17. }
  18. buildCommandDocument(_connection, _session) {
  19. const cmd = { count: this.collectionName };
  20. if (typeof this.options.maxTimeMS === 'number') {
  21. cmd.maxTimeMS = this.options.maxTimeMS;
  22. }
  23. // we check for undefined specifically here to allow falsy values
  24. // eslint-disable-next-line no-restricted-syntax
  25. if (this.options.comment !== undefined) {
  26. cmd.comment = this.options.comment;
  27. }
  28. return cmd;
  29. }
  30. handleOk(response) {
  31. return response.getNumber('n') ?? 0;
  32. }
  33. }
  34. exports.EstimatedDocumentCountOperation = EstimatedDocumentCountOperation;
  35. (0, operation_1.defineAspects)(EstimatedDocumentCountOperation, [
  36. operation_1.Aspect.READ_OPERATION,
  37. operation_1.Aspect.RETRYABLE,
  38. operation_1.Aspect.CURSOR_CREATING,
  39. operation_1.Aspect.SUPPORTS_RAW_DATA
  40. ]);
  41. //# sourceMappingURL=estimated_document_count.js.map