I'm running this query:
Paginate(
Match(
Index("chatMemberships_by_user"),
Ref(Collection('users'), "307731780020994112")
)
)
On this index:
{
name: "chatMemberships_by_user",
serialized: true,
source: "chats",
terms: [
{
field: ["data", "user"]
}
],
values: [
{
field: ["data", "lastActive"]
},
{
field: ["data", "chat"]
},
{
field: ["ref"]
}
]
}
The chatMemberships collection contains these two documents:
{
"ref": Ref(Collection("chatMemberships"), "307917574923878464"),
"ts": 1629911932790000,
"data": {
"user": Ref(Collection("users"), "307731780020994112"),
"chat": Ref(Collection("chats"), "307917574915489856"),
"createdAt": Time("2021-08-25T17:18:52.711023Z"),
"lastActive": Time("2021-08-25T17:18:52.711023Z")
}
},
{
"ref": Ref(Collection("chatMemberships"), "307917574923879488"),
"ts": 1629911932790000,
"data": {
"user": Ref(Collection("users"), "307828268328812611"),
"chat": Ref(Collection("chats"), "307917574915489856"),
"createdAt": Time("2021-08-25T17:18:52.711023Z"),
"lastActive": Time("2021-08-25T17:18:52.711023Z")
}
}
After running the query, the result I get is an empty array instead of an array containing the matching chatMembership document (should be the first one in the screenshot).
{ data: [] }
Any idea on what's causing this? Am I crazy or is this a bug? Thanks!
The problem was that I was referencing the wrong source collection in the index. It should have been “chatMemberships” instead of “chats”.