# Send msg.payload value to another node

**URL:** <https://discourse.nodered.org/t/send-msg-payload-value-to-another-node/43203>\
**Category:** General\
**Created:** [25 March 2021 15:14 UTC](https://discourse.nodered.org/t/send-msg-payload-value-to-another-node/43203 "2021-03-25T15:14:43Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![fikerplunk](https://avatars.discourse-cdn.com/v4/letter/f/e19b73/32.png) [@fikerplunk](https://discourse.nodered.org/u/fikerplunk)\
**Post date:** [25 March 2021 15:14 UTC](https://discourse.nodered.org/t/send-msg-payload-value-to-another-node/43203/1 "2021-03-25T15:14:43Z")

</div>

Hi!  
I have this flow that sends data from the firestore to the split node, which separates each key, so I have this function that creates a string using the keys and sends it to another node of the firestore, so I can put this string in the "collection" field and receive the data for a specific place.

Flow:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/b/ab4a8b9b942cb3b9c2f1e4a0e5f82008f19af42b.png)

Split node:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/0/f0afc1ba3111eb59a55920c97c1bd645842f65f6.png)

Function node:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/7/e7e25093d451460dec1dc4225552b74b50095551.png)

Set node:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/c/fc66878344a9180e3eca31ed7e70fca535bb10a1.png)

The strings apparently work, but when sending to the firestore node, it only returns the values ​​of the last place.

Can someone help me? being new to node-red, I don't know how sending data from one node to another works.

Thanks!

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 March 2021 15:46 UTC](https://discourse.nodered.org/t/send-msg-payload-value-to-another-node/43203/2 "2021-03-25T15:46:27Z")

</div>

The first thing you need to do is to tell us which Firestore node you are using. Probably node-red-contrib-something. I don't use Firestore, but since no-one else has answered possibly no-one here does, but if you tell us which node it is I will have a look and see if I can help.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 March 2021 16:09 UTC](https://discourse.nodered.org/t/send-msg-payload-value-to-another-node/43203/3 "2021-03-25T16:09:14Z")

</div>

Guessing that you might be using node-red-contrib-cloud-firestore the first thing I notice when looking at the readme is

`group` : [boolean] fetch all documents under collections with the above supplied collection name (false by default)

which suggests that to get all documents in the collection you also need to set `msg.firestore.group: true`

---

<div class="post-metadata">

**Author:** ![fikerplunk](https://avatars.discourse-cdn.com/v4/letter/f/e19b73/32.png) [@fikerplunk](https://discourse.nodered.org/u/fikerplunk)\
**Post date:** [25 March 2021 17:24 UTC](https://discourse.nodered.org/t/send-msg-payload-value-to-another-node/43203/4 "2021-03-25T17:24:08Z")

</div>

Sorry, I'm using the node-red-contrib-cloud-firestore.

I left the option "group" as true, but it gives an error in node-red, it appears in the log:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/e/1e4ae5b1b5b5f19084a30bdc15ff2763274340ee.png)

But, I made a new node with the name of the collection that I have in common ("user"), and all the document information really came to me, I would now need to separate this data.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/b/abeedcbb31330337bf7ab28ec061fc11d8f49858.png)

---

<div class="post-metadata">

**Author:** ![fikerplunk](https://avatars.discourse-cdn.com/v4/letter/f/e19b73/32.png) [@fikerplunk](https://discourse.nodered.org/u/fikerplunk)\
**Post date:** [25 March 2021 18:21 UTC](https://discourse.nodered.org/t/send-msg-payload-value-to-another-node/43203/5 "2021-03-25T18:21:30Z")

</div>

I managed using the switch node. But, in the case below, can I take all the objects that start with "User1" and generate a single json object? So there would be two outputs, one json with all "User1" objects and the other with all "User2" objects.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/c/3cc77145a31cdea7e9b8cb8e34b893d91344279f.png)

I'm really sorry for the limited knowledge I still have on node-red.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 March 2021 21:11 UTC](https://discourse.nodered.org/t/send-msg-payload-value-to-another-node/43203/6 "2021-03-25T21:11:45Z")

</div>

> [@fikerplunk](#):
>
> I'm really sorry for the limited knowledge I still have on node-red.

Can I just help to get you off on the correct terminology here which may help to avoid confusion. A JSON object is always a string. It is a string representation of a javascript object. JavaScript Object Notation. So what you are trying to create here is a javascript object, not JSON.

> [@fikerplunk](#):
>
> take all the objects that start with "User1"

In a Function node you can use `Object.entries()` to give you an array of key/value pairs. [Object.entries() - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)  
Then you can go through them and check the keys (which will be "User1", "User1a" etc and build two arrays out of those.

---

<div class="post-metadata">

**Author:** ![fikerplunk](https://avatars.discourse-cdn.com/v4/letter/f/e19b73/32.png) [@fikerplunk](https://discourse.nodered.org/u/fikerplunk)\
**Post date:** [25 March 2021 22:01 UTC](https://discourse.nodered.org/t/send-msg-payload-value-to-another-node/43203/7 "2021-03-25T22:01:30Z")

</div>

What I really wanted to do was find the name of the key, and if that key starts with "User1", create a unique object with everyone, like {"User1a": {}, "User1b": {}, "User1c": {}}, I'm not sure if Object.entries () can help me with this.

Anyway, I am really grateful for the help @Colin, really.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 March 2021 22:07 UTC](https://discourse.nodered.org/t/send-msg-payload-value-to-another-node/43203/8 "2021-03-25T22:07:06Z")

</div>

In a function node put  
`msg.payload = msg.payload.entries()`  
`return msg`

and feed it into a debug node to see what it gives you. It should give you what you are asking for as an array, which you can split into two arrays for user 1 and 2 and then if you really need to put back into an object.

But surely firestore can do this for you if you ask it the right questions.

---

<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:** [24 May 2021 22:07 UTC](https://discourse.nodered.org/t/send-msg-payload-value-to-another-node/43203/9 "2021-05-24T22:07:44Z")

</div>

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