Update record: Firestore datasource - array data type. Did anybody get it to work?

Did anybody successfully update an array (of any type - integer, string, object, or any other type) in Firestore using the Firebase Connector? Could you please share the steps you took?

Also interested in this! Trying to create a user Database and the GET and POST works fine but not the PUT

From what i have understood, appgyver currently only supports put method, when firebase needs patch method, so the only way i have made it work is with direct HTTP request.

For the http set the url like bellow

be sure to choose patch

and for the request body mine is like this, yours is probably different

you can get it by creating a record request in the data configurator like bellow

I hope it helps you

Hi Dimos,

Thanks for your reply. However, appGyver firebase connector does support update record for Firestore. I think it has some issues dealing with arrays. Actually, even Firestore docs recommend modeling your data in another way, if possible. If you try to update any field other than arrays fields, using the connector, it works nice.
The way I’m getting it to work is indeed through a direct HTTP request. It would be nice however to do it all through the connector.

Just to add up to what you posted, when updating firesotre docs, make sure to add, “?updateMask.fieldPaths={yourField}&updateMask.fieldPaths={yourOtherField}&updateMask.fieldPaths={andSoOn}” to the end of your URL, otherwise, you’ll replace the existing doc and loose the fields you don’t put in the request body. E.g. if you have fields “uid” and “name” in your doc, but want to update only the name, you should add to your URL: ?updateMask.fieldPaths=name

2 Likes

Hey, what you say about the documentation is true they say they support put and patch , but because i dont know what the real problem is, the http request is ok for me. Also thanks for the recommendation i didnt know about it !!

1 Like

Hi Dimos,

My HTTP Request for update returns a response code OK and a response body as expected (stored in a page variable to check) but there is no effect on the firestore collection. The exact same setup updates perfectly in Postman. Can you throw some pointers on what might be getting wrong?

Sometimes, you need to reload the page in firestore to show the changes. But if this is not it, maybe you could share your http request url and body, maybe there’s something going on there.

Hi this worked out - was a small mistake

1 Like

5 steps that worked for me:

  1. Create a blank array of objects (page variable) to store picked images (may be more than one) - I call it “imageList”. (Mevi video bit)

  2. Firebase upload - use this formula in “Files to upload”:
    MAP(pageVars.imageList, item[0])

  3. Create another page variable called “contentImagesArray” which is again an array of objects but this time there is a property called StringValue in each of the array objects.

  4. Build the array structure with data that would eventually be written to an array type field of a Firestore collection. The formula to set the page variable is:
    MAP(outputs[“Firebase Storage upload files”].files, {“stringValue”: item.downloadUrl})

  5. Bind record properties in Create Record step with this formula:
    {fields: {contentText: {stringValue: data.UserContentCreatePost.fields.contentText.stringValue}, contentType: {stringValue: “query”}, contentUserId: {stringValue: appVars.userEmail}, contentShow: {booleanValue: true},contentRepliesCount: {integerValue: 0}, createdAt: {timestampValue: NOW()}, contentImages: {arrayValue: {values: pageVars.contentImagesArray}}}}
    The array part is highlighted

Hope this helps.

1 Like

To avoid the deletion of data, you can add the parameter “updateMask” on the end of the PATCH Url with the name of the field to update

"https://firestore.googleapis.com/v1/projects/xxxxxx-xxxxxx/databases/(default)/documents/xxxx/?updateMask.fieldPaths=here_field_to_update"

Firestore doc

The fields to update. None of the field paths in the mask may contain a reserved name.

If the document exists on the server and has fields not referenced in the mask, they are left unchanged. Fields referenced in the mask, but not present in the input document, are deleted from the document on the server.

could you kindly publish some screenshots of this flow (variables and flow)
This would be very helpful.

Thank you !

A solution that has worked for me is to concatenate (using a formula) the array I have stored in local storage to the list I’m using to update the Firestore document.