Conditional action based on whether document already exists

Actions & Logic

I'm trying to create an action that basically says "if a document already exists for this, then update it; else create it". Every combination I have tried either results in the dreaded red "document ID" option in the query parameters or ends up creating one document for all listings and reading that one for everything.

I have a page with a bunch of listings (each with their own "listid" as the main unique identifier). The user can tap "view tags" which takes them to a page with choice chips where the can select the tags that should be associated with that listing. That should update/create a document in the mapdata_tags subcollection (sub of "mapdata" collection) that is unique to that listings document in the mapdata collection.

My update flow is "working" but not correctly as it's updating one document for all listings (and that document shows for all listings). It's "working" in that it successfully updates a/the document in the mapdata_tags subcollection but it won't create a new document under each parent reference.

Technically speaking, the logic is working because A document exists but I can't figure out how to change it to "if a document exists for THIS listid...".

Note: The custom function in the variables was created by another user in the community to strip the non-selected ChoiceChips out and convert the selections to a string to be input as variables in the subcollection.

What have you tried so far?

I've tried just about every combination of variables and query locations I can think of but I either get the dreaded red "Document ID" option or it updates one document for all listings.

Did you check FlutterFlow's Documentation for this topic?
Yes
3
4 replies