Hooks on a bulk operations?

Hello, there is a pattern in guide of how to extend collection with hooks on operations. Example from guide:

class TodosCollection extends Mongo.Collection {
  insert(doc, callback) {
    ...
    return super(doc, callback);
  }
}

Is there a way to extend bulk operations with the same pattern? Maybe @tmeasday could help with this?

Which operation do you want to override? What API do you want?

I think you could do something similar, sure.

Hello, I would like to override .rawCollection().initializeUnorderedBulkOp().insert and I need to have some updated doc data to reuse it within hook. I have a problems to write correct syntax as I not very familiar with classes.

Ok, well you wouldn’t be able to override that (as it’s a property something buried a few levels deep).

But you can just do something like

class TodosCollection extends Mongo.Collection {
  bulkInsert(..) {
    this.rawCollection().initializeUnorderedBulkOp().insert(...)
  }
}
1 Like

Thank you, I understood the main direction.