moscajs / mosca

MQTT broker as a module
mosca.io
3.2k stars 513 forks source link

How to enable multi-collections using Mongo in Mosca ? #663

Closed ghost closed 6 years ago

ghost commented 6 years ago

As i know, mosca can use Mongo to store all messages through ascoltatore. To do that, we need to set configuration as follows:

var ascoltatore = {
  // using ascoltatore
    type: ,
    url: ,
    size: , 
    max: ,
    pubsubCollection: 'mqtt',
    mongo: {}
}

With this setting, all messages are just stored at a mqtt collection of Mongo. So, my question is that how can i store messages on different collections more than one collection ?

Thank you so much.

mcollina commented 6 years ago

messages are not stored. That's a capped collection used for synchronization between different instances.

Why do you want to store messages in different collections?

ghost commented 6 years ago

Thank you for your reply. I might mention wrong concept. Actually, my user case is that i want to create a system which has many users. Each user should have a collection to store all MQTT messages belonging to that user.

mcollina commented 6 years ago

You should use the published event.

ghost commented 6 years ago

Can you help me to explain more ? Thank you so much.

mcollina commented 6 years ago

You do server.on('published', func) and func is a function that stores the message in the user-specific collection.

ghost commented 6 years ago

Thank you so much. It is great recommendation. By the way you mentioned, as i understand, i will store the message in the user-specific collection without the need of using ascoltatore as backend. Is my right ? And i am wondering about performance bw using ascoltatore and without ascoltatore

mcollina commented 6 years ago

Those things are separate. Ascoltatore is needed to do the inter-process communication. This is to store things for your application only,

ghost commented 6 years ago

Thank you for your help :)