How do I select multiple properties from the data
object on an Document?
Is there any way to do this using an FQL Function?
Thanks in advance!
How do I select multiple properties from the data
object on an Document?
Is there any way to do this using an FQL Function?
Thanks in advance!
Map(Paginate(Documents(Collection("guilds"))),Lambda("g", Select("data", Get(Var("g")))))
I have this current function to get all the data
properties from all the documents
Hi @comic-dev I hope I understand your question correctly.
You can return an Array or an Object from an FQL query. And you can use FQL inside of such an Array or Object to return whatever form you would like.
Select
and Let
are the key functions here.
// Can repeat yourself, but that gets tedious
client.query({
field1: Select(['data', 'field1'], Get(Ref(Collection('Thing'), '1234')))
renameWhateverYouWant: Select(['data', 'field2'], Get(Ref(Collection('Thing'), '1234')))
someOtherComplexFQLQuery: Paginate(Union(Match(Index........
})
// So it can be easier to organize with `Let`
// Single document
Let(
{
documentRef: Ref(Collection('Thing'), '1234')
document: Get(Var('documentRef'))
},
{
field1: Select(['data', 'field1'], Var('document'))
renameWhateverYouWant: Select(['data', 'field2'], Var('document'))
someOtherComplexFQLQuery: Paginate(Union(Match(Index........
}
)
// Multiple documents
Map(Paginate(
Documents(Collection('Thing')),
Lambda(
'documentRef',
Let(
{
document: Get(Var('documentRef'))
},
{
field1: Select(['data', 'field1'], Var('document'))
renameWhateverYouWant: Select(['data', 'field2'], Var('document'))
someOtherComplexFQLQuery: Paginate(Union(Match(Index........
}
)
)
))
Ahh, so I can use an array instead of an single value as the first argument of Select
?
And does the field1
refer to the first key or the key with the field1
name?
Yes, there are examples in the docs of this. The first argument to Select
is like a path.
example from the docs:
Select(
['favorites', 'foods', 1],
{ favorites: { foods: ['crunchings', 'munchings', 'lunchings'] } },
)
// "crunchings"
This is what Iām using right now, Thanks so much!
Paginate(Documents(Collection('guilds'))),
Lambda(
'g',
Let(
{ data: Select('data', Get(Var('g'))) },
{
commands: Select('commands', Var('data')),
guild: Select('guild', Var('data'))
}
)
)