How should I return paged data sorted by value after a sum?
For example, documents within the collection have: “user_id, item_a, item_b, item_c”;
I can do something with the example below, add the items and generate the total, but I would not be able to return each page to the user sorted by total (keeping the order between the pages).
Map(
Paginate(Documents(Collection("collection_name"))),
Lambda(
"x",
Let(
{
user_id: Select(['data', 'user_id'], Get(Var("x"))),
a: Select(['data', 'item_a'], Get(Var("x"))),
b: Select(['data', 'item_a'], Get(Var("x"))),
c: Select(['data', 'item_c'], Get(Var("x"))),
},
{
user_id: Var("user_id"),
total: Sum( [Var("a"), Var("b"), Var("c")] )
}
)
)
)
The only way to do this is paging the entire database and displaying part of the data to the user at each request for the entire database???
In this case, I have no way of generating an index with a reverse “true” in total, because “total” is generated at the time of the sum.
Maybe it’s a simple question but I’m adapting to the “fauna” way of doing things, where the thinking is different from SQL. In sql it would be something very simple, I imagine it is the same here too.
Thanks for helping me