How to define dynamic collection and also perform publish, subscribe based on that

Hello,

We try to define the collection from the MongoDB collection.how to achieve publish and subscribe those dynamic collection. Is this the right way to do dynamic architecture?.

Thanks in advance,
Ramesh

well, you can access current collection list etc using for example this package https://github.com/dburles/mongo-collection-instances/

But still you would need to instantiate that given collection on client before calling subscribe.
So you would need to know the name of collection which you want to get on client.
And list of all collections can be provided by package I pasted.

Thanks for your quick reply shock.

But we want to achieve everything as dynamic(including instantiate the collection).

Thanks,
Ramesh.

well, you can dedicate 1 collection to have info about created dynamic collections.
Than publish function to get this collection documents for example AllCollections.
And than on client AllCollections.find().observeChanges where you on every added: react by creating it client side.
Also in AllCollections you would have list of all the names, so you can populate lists by it.

Just dont forget server side when u create new dynamic collection to add it to AllCollections. You can use collection hooks for doing this automatically.
I would even suggest that you just create dynamic collection as a AllCollections insert hook, so you would just need to add it to AllCollections and collection with given name will be automatically created.