estimated_document_count.js 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.EstimatedDocumentCountOperation = void 0;
  4. const command_1 = require("./command");
  5. const operation_1 = require("./operation");
  6. /** @internal */
  7. class EstimatedDocumentCountOperation extends command_1.CommandOperation {
  8. constructor(collection, options = {}) {
  9. super(collection, options);
  10. this.options = options;
  11. this.collectionName = collection.collectionName;
  12. }
  13. async execute(server, session) {
  14. const cmd = { count: this.collectionName };
  15. if (typeof this.options.maxTimeMS === 'number') {
  16. cmd.maxTimeMS = this.options.maxTimeMS;
  17. }
  18. // we check for undefined specifically here to allow falsy values
  19. // eslint-disable-next-line no-restricted-syntax
  20. if (this.options.comment !== undefined) {
  21. cmd.comment = this.options.comment;
  22. }
  23. const response = await super.executeCommand(server, session, cmd);
  24. return response?.n || 0;
  25. }
  26. }
  27. exports.EstimatedDocumentCountOperation = EstimatedDocumentCountOperation;
  28. (0, operation_1.defineAspects)(EstimatedDocumentCountOperation, [
  29. operation_1.Aspect.READ_OPERATION,
  30. operation_1.Aspect.RETRYABLE,
  31. operation_1.Aspect.CURSOR_CREATING
  32. ]);
  33. //# sourceMappingURL=estimated_document_count.js.map