Send notification to users from server side when a data is created into collection

HI,
I need to send notification all users when a new collection is created where the collection is visible to all
and also notify a specific user when a another collection is created from API(by using restivus)

can anyone help me on this, please

Thank you.

Hello, you can implement that with collections hooks, check this package: https://github.com/matb33/meteor-collection-hooks (after insert appears to be what you are looking for)

After using it you just need to implement your notification mechanism. If you want to use Push Notification with Cordova Mobile Apps check this package https://github.com/raix/push

If you have troubles let me know.

1 Like

I am not sure this is what he is asking for. Collection-hook only helps with the creation of documents within a collection, not for collection creation ?

If I understood your request properly, I am thinking you could extend Meteor.Collection with your own logic. I have never used it for this specific purpose, but to implement my own hooks on document manipulation without relying on third-party packages, and it worked great.

From memory, you can do things like this:

import { Meteor } from 'meteor/meteor'

class extendedCollection extends Meteor.Collection {
    constructor(collectionName, options) {
       // Do your stuff here
       super(collectionName, options);
    }
}

export default extendedCollection

And then to use it

import extendedCollection from 'wherever/it/s/at';

const yourActualCollection = new extendedCollection('you-actual-collection');

So, pretty simple stuff. But untested :smiley:

1 Like

Couldn’t you just have a collection which holds the keys to all your collections?

Then in the method that creates a new collection, add the name/key to the Collections collection and use Meteor’s pub/sub to send details to users?

You could pair it with collection hooks on the Collections collection to trigger push notifications like @filipenevola suggests.

You could also extend the Collection class to automatically add new collections to the Collections collection, so you can encapsulate that logic as @pdecrat suggests

3 Likes