Send msg.payload value to another node

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.


Split node:

Function node:

Set node:

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.


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.

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 true

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:

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.

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.

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.

In a Function node you can use Object.entries() to give you an array of key/value pairs. Object.entries() - JavaScript | MDN
Then you can go through them and check the keys (which will be "User1", "User1a" etc and build two arrays out of those.

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.

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.

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