New to FaunaDB and have been able to get the basic stuff working (creating and reading collections and indexes.) I am now trying to create some data references in my collections and I am a little lost on how to go about it. Most of the examples I find have the References hardcoded, and in my case, I don’t have this data. I have some keys that I can use to query an index, but not sure how to use that to get a Ref to pass into my other query.
Say I have a collection of Shop objects with a unique “key” data attribute. I also have an index called shops_by_key
.
I also have a collection called “Carts”, which will be used to hold references to Shops. So a Cart has-many Shops. In my head, the FQL document/entry looks something like this:
{
"ref": Ref(Collection("carts"), "287656564382237192"),
"ts": 1610730727970000,
"data": {
shopRefs: [
Ref(Collection("shops"), "287656564382237194"),
Ref(Collection("shops"), "287656564382237195"),
Ref(Collection("shops"), "287656564382237197"),
....
]
}
}
Within my app, I am making a request that sends over a collection of shop objects, but I have no reference to the Ref ID in fauna anywhere. I just have the unique shop “key” that I can use to look up the shop from the “shop_by_key” index.
So question is, how do I use this information to construct a Create/Update command using FQL, which takes an array of shop objects (with unique key), looks up each shop from the “shop_by_key” index, and passes those References into the Create Cart query.
Hope I was able to explain that so that it makes sense. Thank you