Meteor-Community-Packages / meteor-collection-hooks

Meteor Collection Hooks
https://atmospherejs.com/matb33/collection-hooks
MIT License
657 stars 92 forks source link

Collection hook not called on second application #205

Closed cyclops24 closed 7 years ago

cyclops24 commented 7 years ago

Hi guys, I have an application written with Meteor 1.4 and run it on port 3000 (called A) know I want use A application database in another application (called B). In B console I set MONGO_URL like this:

export MONGO_URL=mongodb://localhost:3001/meteor

And then run that on port 5000. I have some collection hook on app A and also some collection hook on app B but hooks only called in app A.

For example in A we have:

collections.notes.after.update(function(userId, doc, fieldNames, modifier, options) {
    console.log("notes updated in A hook");
    console.log(doc);
}

And in B we have:

collections.notes.after.update(function(userId, doc, fieldNames, modifier, options) {
    console.log("notes updated in B hook");
    console.log(doc);
}

But it's only log notes updated in A hook.

How to fix it?

Related StackOverflow question Related Forum question

/cc: @matb33 /cc: @evliu /cc: @nate-strauser /cc: @mizzao

namirsab commented 7 years ago

Well, hooks are happening in the app level not at the database level. That means that it does not matter whether you link to apps via the same database. Hooks wrote in app "A" will be run when the app "A" makes a call to collections.notes.update. Hooks written in app "B" will only be called when app "B" makes a call to collections.notes.update.

cyclops24 commented 7 years ago

@namirsab, Oh man. It's a good note. So this is normal with collection-hook. @namirsab can you suggest any working way for my situation? Or maybe some keyword for searching about this.

namirsab commented 7 years ago

@cyclops24 there are several possibilities.

Another solution could be to write a data-layer app you will use to mutate your data. This app will give the other apps an API to change the data, and internally this will be the only one that will have the hooks.

As you can see there are some possibilities, but you need to analyze your case and then decide.

i hope it helps :smile:

I close the issue because i think its solved :smile:

cyclops24 commented 7 years ago

Thanks @namirsab , You save me man. 😉