count.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.CountOperation = void 0;
  4. const command_1 = require("./command");
  5. const operation_1 = require("./operation");
  6. /** @internal */
  7. class CountOperation extends command_1.CommandOperation {
  8. constructor(namespace, filter, options) {
  9. super({ s: { namespace: namespace } }, options);
  10. this.options = options;
  11. this.collectionName = namespace.collection;
  12. this.query = filter;
  13. }
  14. async execute(server, session) {
  15. const options = this.options;
  16. const cmd = {
  17. count: this.collectionName,
  18. query: this.query
  19. };
  20. if (typeof options.limit === 'number') {
  21. cmd.limit = options.limit;
  22. }
  23. if (typeof options.skip === 'number') {
  24. cmd.skip = options.skip;
  25. }
  26. if (options.hint != null) {
  27. cmd.hint = options.hint;
  28. }
  29. if (typeof options.maxTimeMS === 'number') {
  30. cmd.maxTimeMS = options.maxTimeMS;
  31. }
  32. const result = await super.executeCommand(server, session, cmd);
  33. return result ? result.n : 0;
  34. }
  35. }
  36. exports.CountOperation = CountOperation;
  37. (0, operation_1.defineAspects)(CountOperation, [operation_1.Aspect.READ_OPERATION, operation_1.Aspect.RETRYABLE]);
  38. //# sourceMappingURL=count.js.map