delete_one.js 680 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. const OperationBase = require('./operation').OperationBase;
  3. const deleteCallback = require('./common_functions').deleteCallback;
  4. const removeDocuments = require('./common_functions').removeDocuments;
  5. class DeleteOneOperation extends OperationBase {
  6. constructor(collection, filter, options) {
  7. super(options);
  8. this.collection = collection;
  9. this.filter = filter;
  10. }
  11. execute(callback) {
  12. const coll = this.collection;
  13. const filter = this.filter;
  14. const options = this.options;
  15. options.single = true;
  16. removeDocuments(coll, filter, options, (err, r) => deleteCallback(err, r, callback));
  17. }
  18. }
  19. module.exports = DeleteOneOperation;