collections.js 1.2 KB

1234567891011121314151617181920212223242526272829
  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.AbstractOperation {
  8. constructor(db, options) {
  9. super(options);
  10. this.options = options;
  11. this.db = db;
  12. }
  13. execute(server, session, callback) {
  14. const db = this.db;
  15. // Let's get the collection names
  16. db.listCollections({}, { ...this.options, nameOnly: true, readPreference: this.readPreference, session }).toArray((err, documents) => {
  17. if (err || !documents)
  18. return callback(err);
  19. // Filter collections removing any illegal ones
  20. documents = documents.filter(doc => doc.name.indexOf('$') === -1);
  21. // Return the collection objects
  22. callback(undefined, documents.map(d => {
  23. return new collection_1.Collection(db, d.name, db.s.options);
  24. }));
  25. });
  26. }
  27. }
  28. exports.CollectionsOperation = CollectionsOperation;
  29. //# sourceMappingURL=collections.js.map