options_operation.js 894 B

1234567891011121314151617181920212223242526272829303132
  1. 'use strict';
  2. const OperationBase = require('./operation').OperationBase;
  3. const handleCallback = require('../utils').handleCallback;
  4. const MongoError = require('../core').MongoError;
  5. class OptionsOperation extends OperationBase {
  6. constructor(collection, options) {
  7. super(options);
  8. this.collection = collection;
  9. }
  10. execute(callback) {
  11. const coll = this.collection;
  12. const opts = this.options;
  13. coll.s.db.listCollections({ name: coll.collectionName }, opts).toArray((err, collections) => {
  14. if (err) return handleCallback(callback, err);
  15. if (collections.length === 0) {
  16. return handleCallback(
  17. callback,
  18. MongoError.create({ message: `collection ${coll.namespace} not found`, driver: true })
  19. );
  20. }
  21. handleCallback(callback, err, collections[0].options || null);
  22. });
  23. }
  24. }
  25. module.exports = OptionsOperation;