is_capped.js 1.2 KB

123456789101112131415161718192021222324252627282930
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.IsCappedOperation = void 0;
  4. const error_1 = require("../error");
  5. const operation_1 = require("./operation");
  6. /** @internal */
  7. class IsCappedOperation extends operation_1.AbstractOperation {
  8. constructor(collection, options) {
  9. super(options);
  10. this.options = options;
  11. this.collection = collection;
  12. }
  13. execute(server, session, callback) {
  14. const coll = this.collection;
  15. coll.s.db
  16. .listCollections({ name: coll.collectionName }, { ...this.options, nameOnly: false, readPreference: this.readPreference, session })
  17. .toArray((err, collections) => {
  18. if (err || !collections)
  19. return callback(err);
  20. if (collections.length === 0) {
  21. // TODO(NODE-3485)
  22. return callback(new error_1.MongoAPIError(`collection ${coll.namespace} not found`));
  23. }
  24. const collOptions = collections[0].options;
  25. callback(undefined, !!(collOptions && collOptions.capped));
  26. });
  27. }
  28. }
  29. exports.IsCappedOperation = IsCappedOperation;
  30. //# sourceMappingURL=is_capped.js.map