I’m still confounded by what I think should be simple, and it’s holding me back.
Let’s say, I’ve got an index like this:
{
name: "recipes_by_chef_id",
unique: false,
serialized: true,
source: "Recipe",
values: [
{
field: ["data", "chefId"]
},
{
field: ["ref"]
}
]
}
Where chefId
is a unique UUID that comes from the app’s auth provider (Cognito).
The following query works, but it gets all of the documents, which I don’t want:
q.Map(
q.Paginate(q.Match(q.Index("recipes_by_chef_id"))),
q.Lambda(["chefId", "ref"], q.Get(q.Var("ref")))
)
I got this pattern from the docs here, right were it says: “The fix is easy. Copy the following query, paste it into the shell, and run it:”
What I want is to query the index and return all documents that match a specific chefId
.
I got the following pattern from the very helpful (and patient) @ptpaterson, though I’ve yet to find this (arrow function) pattern documented. If that exists, please send me there!
q.Map(
q.Filter(
q.Paginate(q.Match(q.Index("recipes_by_chef_id"))),
(chefId, ref) => q.Equals(chefId, searchChefId)
),
(chefId, ref) => q.Get(ref)
)
For the record, searchChefId
, is provided as a variable to the function running this query. I’ve even hard coded it, to test, and it still doesn’t work when I do that.
Weirdly, this pattern works for other queries on other indexes I’ve created, for example, with this index:
{
name: "user_by_secret_code",
unique: false,
serialized: true,
source: "User",
values: [
{
field: ["data", "secretCode"]
},
{
field: ["ref"]
}
]
}
The following query works flawlessly:
q.Map(
q.Filter(
q.Paginate(q.Match(q.Index("user_by_secret_code"))),
(secretCode, ref) => q.Equals(secretCode, searchCode)
),
(secretCode, ref) => q.Get(ref)
)
);
searchCode
, here, would be the same thing as searchChefId
in the previous example.
Because the latter works and the former doesn’t I’m in a quandary. They seem practically identical to me.
Surely, I’m doing something wrong, but no matter how hard I scour the docs and Google, I haven’t the foggiest ideas on how to trouble shoot this.
Any help would be greatly appreciated.