# Adding multiple MQTT data to one function node

**URL:** https://discourse.nodered.org/t/adding-multiple-mqtt-data-to-one-function-node/31190
**Category:** General
**Created:** [5 August 2020 16:50 UTC](https://discourse.nodered.org/t/adding-multiple-mqtt-data-to-one-function-node/31190 "2020-08-05T16:50:05Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![SinZapatillas](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@SinZapatillas](https://discourse.nodered.org/u/SinZapatillas)
#### Post date: [5 August 2020 16:50 UTC](https://discourse.nodered.org/t/adding-multiple-mqtt-data-to-one-function-node/31190/1 "2020-08-05T16:50:06Z")

</div>

Hi! I am new to the Forum.  
I am creating an IoT app which register certain data into a database from an smart rollator. I have 4 sensors in 4 different topics. I want all of the data to be inserted simultaneously in the database, so I am joining all the mqtt outputs into a function node with the INSERT INTO chart (xxxx) VALUES (a,b,c,.....) inside. My problem is that I don´t know how to give each MQTT output data a different name (a, b, c) so I can do it. All outputs are are called with the same object name: msg.

I am attaching a screenshot of the flow:

 ![flujo](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/8/d80a42e8e73e52bf1aa15c60397b55f3789299d9.png)

I am pretty sure it must be pretty easy but my knowledge in Javascript its non-existing ( I only know C++ ).

Any help would be really useful! Thanks in advance 🙂

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [5 August 2020 16:57 UTC](https://discourse.nodered.org/t/adding-multiple-mqtt-data-to-one-function-node/31190/2 "2020-08-05T16:57:56Z")

</div>

See [this article in the cookbook](https://cookbook.nodered.org/basic/join-streams) for an example of how to join messages into one object.

[This video](https://www.youtube.com/watch?v=t8T-JMnQHMk&list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6&index=18) describes it very well too.

once you have all the data in a single `msg` object, you can use a template node or a function to generate the SQL statement.

---

<div class="post-metadata">

### Author: ![SinZapatillas](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@SinZapatillas](https://discourse.nodered.org/u/SinZapatillas)
#### Post date: [5 August 2020 17:32 UTC](https://discourse.nodered.org/t/adding-multiple-mqtt-data-to-one-function-node/31190/3 "2020-08-05T17:32:29Z")

</div>

Thanks Steve!

And how can I access to each part of the new object created in the function node? The object is:  
 ![duda2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/c/bc18966364131cb2e16e4c1d22afd4073969bafa.png)

I tried msg.payload.ID/Fuerza/Izq but it does not work.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [5 August 2020 17:37 UTC](https://discourse.nodered.org/t/adding-multiple-mqtt-data-to-one-function-node/31190/4 "2020-08-05T17:37:38Z")

</div>

good stuff, you made it this far 🙂

That video was one of about 18 short videos which are really worth watching - you will get a whole bunch of good tips.

If you view the [8th video](https://www.youtube.com/watch?v=TDxL02SInps&list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6&index=8), at about the 1:10 mark, you will see where Nick hovers over the debug message and copies the path to an item.

that is essentially what you need to do to get the path to the value.

Have a watch (its like mins long or something)

[this article](https://nodered.org/docs/user-guide/messages) is also helpfull on the same subject

---

<div class="post-metadata">

### Author: ![SinZapatillas](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@SinZapatillas](https://discourse.nodered.org/u/SinZapatillas)
#### Post date: [5 August 2020 17:40 UTC](https://discourse.nodered.org/t/adding-multiple-mqtt-data-to-one-function-node/31190/5 "2020-08-05T17:40:44Z")

</div>

Great thanks!  
I see there is a lot of information but sometimes its hard to get exactly what you want. I will watch them.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [5 August 2020 17:44 UTC](https://discourse.nodered.org/t/adding-multiple-mqtt-data-to-one-function-node/31190/6 "2020-08-05T17:44:12Z")

</div>

> [@SinZapatillas](#):
>
> I tried msg.payload.ID/Fuerza/Izq but it does not work.

I forgot to say - you have to use the JavaScript property accessor feature called "[bracket notation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors#Description)"  
so this example would be `msg.payload["ID/Fuerza/Izq"]`

but watch the video - it will save you having to remember the above info!

> [@SinZapatillas](#):
>
> I see there is a lot of information but sometimes its hard to get exactly what you want

Sometimes the blocker is not knowing what things are called (object / property, array / element, etc) - get them straight and you're half way there.

---

<div class="post-metadata">

### Author: ![SinZapatillas](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@SinZapatillas](https://discourse.nodered.org/u/SinZapatillas)
#### Post date: [6 August 2020 10:16 UTC](https://discourse.nodered.org/t/adding-multiple-mqtt-data-to-one-function-node/31190/7 "2020-08-06T10:16:06Z")

</div>

Thanks!

Sure will 😉

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [5 October 2020 10:16 UTC](https://discourse.nodered.org/t/adding-multiple-mqtt-data-to-one-function-node/31190/8 "2020-10-05T10:16:13Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
