What is the resource schema for this firestore document structure❓

Hey all,
I have this doc structure in firestore. The list of objects may be growing in the future.

image

I can’t figure out the right resource schema in the appgyver data resource so that I get this json schema:

array pricePoints
[
 {count: 1,
 price: 15},

 {count: 2,
 price: 25},

 {count: 2,
 price: 50},
]

Any clue for configuring the resource schema welcome, please!

Can you expand one of the fields in firebase so I can see the field-type in firebase? It looks like it is a Json object as a string but it might be a map.

Try setting the value type as list of objects

image

pricePoint is an array of objects {count, price} (map in Firebase).

How/where do I do that? I tried that in the configuration data resource console. No list option, only object:

No you should do it in the object nested under the main collection

When I get to my PC I will make a screen shot for you.

Like this? But I can add only one {id, price, count} object, I have a few {price, count} objects in firebase.

Note: before moving too far, the purpose is to dynamically bind those {price, count} objects to a slider field so the slider steps and values are those of the {price, count} objects in the list.

After you add one object, you can keep adding them and change the value type for each value of object.

I omitted to specify that the price in each object, eg: {15$, count}, {25$, count},… is “hard coded”. It is admin input. When users register a new service, they select a price point from a dropdown list. Then I do a count per price point hence that document with pre defined list of objects {price, count}.

So what to do in the data resource configuration?
Do I just add the object {price, count} once, like I show you in my past screenshot?
I come from a MySQL background so I’m quite lost with non relational data.

I still have not made it to my PC

Like this:

price points (list)

I am pretty sure “id” should be another list of objects

under id, add objects:

price(set type to number)

count(set type to number)

I will still try to make a screenshot when I get to my PC. Been a crazy day.

Like this? I guess I just do a repeat in the composer for working with the other {price, count} objects?



When I build a MAP(pricePoints) formula, I see this preview, which seems wrong and overly complicated:
image

This is what I need:

array pricePoints
[
 {count: 1,
 price: 15},

 {count: 2,
 price: 25},

 {count: 2,
 price: 50},
]

Yes, like that. That is a list. So it returns the same schema as you would need. It only shows one object, as it is only the schema. If you do a test get record logic flow with your specific document id and output that to a pagevar or alert you can see that the output should be the list. Even if you modify in Firestore, it will return the new list with the new objects.

1 Like

Thank you!
What formula do you recommend for the values of the slider field (as many steps as there are objects and each step having {price, count} value?

It most probably be WITH_ITEM(list, object)
There may be a few issues. If any binding requires “inversible formula” then create a page variable for that specific value and bind that to the property. And do the change of data resource value on the canvas after the “page variable changed” event.

1 Like

I’ve got this preview with MAP()
Since I’m new to all this: is the red color normal? What about the Validation warning message in orange?

Will try with WITH_ITEM() now, thanks!

Man, you want to retrieve 1 object from that list. MAP() formula returns a list. So the very least is that you would put a [0] at the end of your formula… But that is no best practice.
Also you assign this value to some variable that is of number type. But what you build with the MAP() is of string type.

So actions to do:

  1. Change the type of the value that you want to assign to a “text”.
  2. Instead of the MAP() use simply the second part of your formula where you set your value.

Now a few notes.
This will return only the first object from your whole list.
It seems to me that you want to repeat a component with this data, for that you would need to omit the [0]s and also refer to the list of the MAP() function as “item”.
So you can have something like this:

MAP(data.fetch.pricePoints, item.price+"€ ("+item.count+")")

Above formula applies only if you don’t have the “I’d” property. Because what I seem to understand is that you still have your over complicated schema from the reply above in place…