moscajs / aedes-persistence-mongodb

MongoDB persistence for Aedes
MIT License
14 stars 16 forks source link

Only retained collection working #25

Closed robertsLando closed 4 years ago

robertsLando commented 4 years ago

Since I'm using Aedes I see that the only one collection that appears is retained. Where are packets, subscriptions, clients etc?

I set up aedes as follow:

    var aedesSettings = {
    port: 1883,
    persistence: require('aedes-persistence-mongodb')({
      db: mongoose.connection.useDb('aedesMqtt')
    })
  };

  broker = require('aedes')(aedesSettings);
robertsLando commented 4 years ago

@mcollina Any update on this?

mcollina commented 4 years ago

I'd recommend you to check out the code and send a docs PR explaining the collections. The code is fully tested, so you should be able to read the source. I have no time to document how this module works internally.

robertsLando commented 4 years ago

@mcollina Seems that this happens if you don't specify a ttl in options. If I add ttl options all collections are working

robertsLando commented 4 years ago

Based on this. I think that existing ttl options should expect a different ttl for retained messages.

I suggest something like:

ttl: {
      packets: {
           incoming: 300,
           outgoing: 500,
           will: 500,
           retained: -1 //persistent
      }
      subscriptions: 300
  }

If the ttl is -1 the index should not be created. To keep back compatibility a check can be done at start to use that ttl value for all packets so:

ttl: {
      packets: 300,
      subscriptions: 300
  }

// it's like:

ttl: {
      packets: {
           incoming: 300,
           outgoing: 300,
           will: 300,
           retained:  300
      }
      subscriptions: 300
  }