Hi i have created two collections Orders and Customers.For time being i’m pasting document’s of both collections with same CustomerID which i need to join.
Orders Collection:
{
"ref": Ref(Collection("Orders"), "366856354920398928"),
"ts": 1686123836000000,
"data": {
"OrderId": 10308,
"CustomerID": 2,
"OrderDate": Date("1996-09-18")
}
}
Customers Collection:
{
"ref": Ref(Collection("Customers"), "366856746958848080"),
"ts": 1686123551520000,
"data": {
"CustomerID": 2,
"CustomerName": "Ana Trujillo Emparedados y helados",
"ContactName": "Ana Trujillo",
"Country": "Mexico"
}
}
I have created the indexes for both collections by CustomerID term using below queries.
Index Creation by CustomerID for Customers Collection:
CreateIndex({
name: "customers_by_customerId",
source: Collection("Customers"),
terms: [{ field: ["data", "CustomerID"] }]
})
Index Creation by CustomerID for Orders Collection:
CreateIndex({
name: "orders_by_customerId",
source: Collection("Orders"),
terms: [{ field: ["data", "CustomerId"] }]
})
I have used the below query for joining above two collections.
Map(
Paginate(
Join(
Match(Index("customers_by_customerId"), 2),
Index("orders_by_customerId")
)
),
Lambda(["customerRef", "orderRef"], {
customer: Get(Var("customerRef")),
order: Get(Var("orderRef"))
})
)
Output for the above query is data key pointing to empty array.
Map(
Paginate(
Join(
Match(Index("customers_by_customerId"), 2),
Index("orders_by_customerId")
)
),
Lambda(["customerRef", "orderRef"], {
customer: Get(Var("customerRef")),
order: Get(Var("orderRef"))
})
)
{
data: []
}
What was the reason for getting a data key with empty array and how to resolve it?