I have a database with the following structure:
+----------------+ +----------------+ +----------------+
| foo | | foo_bar | | bar |
+-------+--------+ +-------+--------+ +-------+--------+
| _id | ID |---┐ | _id | ID | ┌---| _id | ID |
| date | Time | └-->| fooID | ID | | | field | string |
+-------+--------+ | barID | ID |<--┘ +-------+--------+
| field | string |
+-------+--------+
There’s an index on foo_bar
to allow retrieval of junction documents based on barID
and field
:
{
name: "foo_bar_by_field_and_bar",
source: Collection("foo_bar"),
terms: [{ field: ["data", "field"] }, { field: ["data", "barID"] }],
values: [{ field: ["ref"] }]
}
This is coupled with a function to retrieve foo
:
Query(
Lambda(
[...],
Map(
Paginate(Match(Index("foo_bar_by_field_and_bar"), [..., ...])),
Lambda(
["ref"],
Get(
Ref(
Collection("foo"),
Select(["data", "fooID"], Get(Var("ref")))
)
)
)
)
)
)
This works however I’d like to retrieve foo
s reverse ordered by date
. What’s the best way to do this?