FQL: Query order by nested document value

I have the following schema:


with a One-to-Many relationship between Board and Column and in Fauna the collections are generated like this: only the Column has a reference to the Board.
How can I create a resolver function where I get the Board with a specific name that retrieves also all the columns of the board where the columns are ordered by the weight value (is a property of Column document)

Column:

Hi @ClaudiaGiv and welcome!

would you post a Board document sample as well?

Thanks,

Luigi

1 Like

image

Hi @ClaudiaGiv

you can just create couple of indexes:

 CreateIndex({name:"refByTitle",source:Collection('Board'),terms:[{field:['data','title']}]})

and

CreateIndex({name:"docByref",source:Collection('Column'),terms:[{field:['data','board']}],values:[{field:['data','weight']},{field:['data','wip']},{field:['data','title']},{field:['data','wipLimit']},{field:['data','description']}]})

and use Join() to query documents:

Paginate(
  Join(
    Match('refByTitle','Value Factory'),
    Index('docByref')
  )
)

if you want to retrieve documents with the opposit order, just create the index that way:

CreateIndex({name:"docByrefDesc",source:Collection('Column'),terms:[{field:['data','board']}],values:[{field:['data','weight'],reverse:true},{field:['data','wip']},{field:['data','title']},{field:['data','wipLimit']},{field:['data','description']}]})

Hope this helps,

Luigi