How to add to array in firestore?

:bullseye: What is your goal?

Hi, I’m desperate. I tried almost every variation of solution.

I query document from firestore with Array of users. I want to add new user to the end of array. But when I just use “add” function, all values in saved array are on position (key) [0] separated with “,”.

Like

[0] user 1
[1] user 2
[2] user 3

Turns into

[0] user 1, user 2, user 3,

How to solve this? Im going mad.

:thinking: What is the problem & what have you tried?

map, add, to array, JSON, Iterator + Array aggregator,

Hi @Patrik_Drab. Welcome to the community.

How is the scenario structured? Can you share some screenshots? There are thousands of ways to use those modules/functions. It’s hard to help you without seeing your use case.

Can you see type Array in the output? How and where are you using add()?

@damato

Actually problem isn’t in adding. Also when I just query a document with array and try to save the array into the same document, this happens.

I’m sending photos of “update document” , before and after photo of document.

You’re passing an Array as Text (String Value) to the module. Some automatic conversion is taking place.
Try to set the Value type to Array.

Actually type of value is Array, just value of item is string . It can’t be array, there is no choice.

Toggle the “Map” switch and the Value type choice will go away. Just map the array pill to the field.

Already tried to map Value, to map value type, to map item type, to map item, always end up with error like this: “Array of objects expected.” But its fucking array…why make.com make this so complicated. This is totally easy task - just save array ffs.

It’s because you’re passing an array of strings and it’s expecting an array of objects. Something like

[{“stringValue”:”A”},{“stringValue”:”B”}]

But you probably don’t need that.

Since you are using the correct uzivatele[] array, you should not need to do that.

Instead, just leave the first Value type as Array, like the picture above. Then, on Value, toggle map on and map the uzivatele[] array there.

If you toggle map off, it’ll understand that you’re mapping individual values of the array.

I already tried trial-error on mapping every level and every pill. It just doesn’t work.. i spent literally hours to try every possible setting.

You should leave Value type as Array. Your array pill must be mapped to Value.

Already tried also this possibility. Error “value expected array”.

Oh, now I see. I managed to reproduce your issue.

You can’t pass a simple Make array to Firestore, even one that came from Firestore itself (users).

Firestore’s API doesn’t want ["A", "B"] ; it wants [{"value": "A", "valueType": "stringValue"}, {"value": "B", "valueType": "stringValue"}] .

Thus, you need to build that array yourself and pass it to Firestore the way I told you before:

The simplest way to do this is to add an Iterator over the users[] array, adding the value you want to the array with add(), then place an Aggregator after it, where the target structure is the Update a document module.

Iterator:

Aggregator:

Tip: If the “value” does not appear on the list for the Text field, add it manually with {{X.value}}, where X is the Iterator’s number.

That forces Make to produce the correct input for the Firestore API.

@damato