Given
Index
q.CreateIndex({
name: 'tokensByUserId',
source: q.Collection('userTokens'),
terms: [{ field: ['data', 'userId'] }],
values: [
{ field: ['data', 'organizationId'] },
{ field: ['ref'] }
]
});
Question
q.Map(
q.Paginate(q.Match(q.Index("tokensByUserId"), "0123456789")),
q.Lambda(
["_", "ref"],
q.Let(
{
result: q.Select(["data", q.Get(q.Var("ref"))]),
organization: q.Select(
["data"],
q.Get(q.Select(["organizationId"], q.Var("result")))
),
},
q.Var("organization")
)
)
);
q.Map(
q.Paginate(q.Match(q.Index("tokensByUserId"), "0123456789")),
q.Lambda(
["organizationId", "ref"],
q.Select(
["data"],
q.Get(q.Ref(q.Collection("organizations"), q.Var("organizationId")))
)
)
);
On the first query, Let’s pretend that the organizationId
is not returned on the values of the index, so I had to Get
the result and then Select
the organizationId
.
On the second query, I did not have to do Get
twice, because I already have the organizationId
which was returned by the Index
.
If there’s only one document currently on the database (on all tables), how many reads would be incurred for each of the queries?
I’m trying to figure out if values
on index
can help me reduce read ops.