Automatic insert from a collection to another

Hi all, im using perak/meteor-mqtt-collection so when i get a mqtt message it’s inserted into a specified collection in this way:
id (id of the document)
topic (topic that the message was published to)
message ()
|
data of the message(like value : 30 or json format)

what i need is to insert (or update) this data into a different collection and delete the original message…

can you suggest a way to do that?

Maybe look into leveraging matb33:collection-hooks on the server. When your collection receives an MQTT topic you could fire an .after.insert or .after.update collection hook to handle copying the necessary data into your separate collection.

1 Like

Check out meteor-collection-hooks

1 Like

thanks for the hint, i get it working with

Devices.before.upsert(function (userId, selector, modifier, options) {
modifier.$set = modifier.$set || {};
modifier.$set = modifier.$set.message;
});

no need to deleting the original document with this.