collections.js 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.CollectionsOperation = void 0;
  4. const collection_1 = require("../collection");
  5. const operation_1 = require("./operation");
  6. /** @internal */
  7. class CollectionsOperation extends operation_1.AbstractCallbackOperation {
  8. constructor(db, options) {
  9. super(options);
  10. this.options = options;
  11. this.db = db;
  12. }
  13. executeCallback(server, session, callback) {
  14. // Let's get the collection names
  15. this.db
  16. .listCollections({}, { ...this.options, nameOnly: true, readPreference: this.readPreference, session })
  17. .toArray()
  18. .then(documents => {
  19. const collections = [];
  20. for (const { name } of documents) {
  21. if (!name.includes('$')) {
  22. // Filter collections removing any illegal ones
  23. collections.push(new collection_1.Collection(this.db, name, this.db.s.options));
  24. }
  25. }
  26. // Return the collection objects
  27. callback(undefined, collections);
  28. }, error => callback(error));
  29. }
  30. }
  31. exports.CollectionsOperation = CollectionsOperation;
  32. //# sourceMappingURL=collections.js.map