update_many.js 811 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. const OperationBase = require('./operation').OperationBase;
  3. const updateCallback = require('./common_functions').updateCallback;
  4. const updateDocuments = require('./common_functions').updateDocuments;
  5. class UpdateManyOperation extends OperationBase {
  6. constructor(collection, filter, update, options) {
  7. super(options);
  8. this.collection = collection;
  9. this.filter = filter;
  10. this.update = update;
  11. }
  12. execute(callback) {
  13. const coll = this.collection;
  14. const filter = this.filter;
  15. const update = this.update;
  16. const options = this.options;
  17. // Set single document update
  18. options.multi = true;
  19. // Execute update
  20. updateDocuments(coll, filter, update, options, (err, r) => updateCallback(err, r, callback));
  21. }
  22. }
  23. module.exports = UpdateManyOperation;