count.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. execute(server, session, callback) {
  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. super.executeCommand(server, session, cmd, (err, result) => {
  33. callback(err, result ? result.n : 0);
  34. });
  35. }
  36. }
  37. exports.CountOperation = CountOperation;
  38. (0, operation_1.defineAspects)(CountOperation, [operation_1.Aspect.READ_OPERATION, operation_1.Aspect.RETRYABLE]);
  39. //# sourceMappingURL=count.js.map