Closed MaxmaxmaximusGitHub closed 4 years ago
Could you please explain with a bit more details what you're trying to do? Is this a bug, a feature request or rather a question about the package which would need some documentation?
I try extend all collections.
Per the documentation, it looks like you can define a hook option globally to all collections, but not add an actual hook globally to all collections. Why would you want to add the same hook to every collection globally? Sounds like something more suited for the autovalue
options of simpl-schema perhaps? Like adding default values (e.g. userId, timestamps, etc.) on inserts, updates, etc.
You could extend Mongo.Collection
directly and then use that to create your collection instances.
export Class MyCollection extends Mongo.Collection {
insert(...args) {
//do whatever before the insert happens
super.insert(...args)
}
}
import { MyCollection } from ' ./path/to/MyCollectionClass';
let extendedCollectionInstance = new MyCollection('test');
extendedCollectionInstance.insert({ test: true })
@copleykj how i can extend existing collections, created not by me?
solution:
for collection in Mongo.Collection.getAll()
collection.before.insert # e.t.c.
Mongo.Collection.before.insert is not a function