estimated_document_count.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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.CommandCallbackOperation {
  8. constructor(collection, options = {}) {
  9. super(collection, options);
  10. this.options = options;
  11. this.collectionName = collection.collectionName;
  12. }
  13. executeCallback(server, session, callback) {
  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. super.executeCommandCallback(server, session, cmd, (err, response) => {
  24. if (err) {
  25. callback(err);
  26. return;
  27. }
  28. callback(undefined, response?.n || 0);
  29. });
  30. }
  31. }
  32. exports.EstimatedDocumentCountOperation = EstimatedDocumentCountOperation;
  33. (0, operation_1.defineAspects)(EstimatedDocumentCountOperation, [
  34. operation_1.Aspect.READ_OPERATION,
  35. operation_1.Aspect.RETRYABLE,
  36. operation_1.Aspect.CURSOR_CREATING
  37. ]);
  38. //# sourceMappingURL=estimated_document_count.js.map