我对动物群很陌生,所以请原谅我。我想做一个查询,返回文档中的嵌套文档。我通过下面创建的索引访问包含嵌套文档的初始文档:
Get(Match(Index("account-user_by_sub"), "google-oauth2|10233470761")该索引返回以下内容:
{
ref: Ref(Collection("account-users"), "325230990747238466"),
ts: 1646423292780000,
data: {
userAccount: Ref(Collection("user-accounts"), "325134359745003585"),
firstName: "firstName",
lastName: "lastName",
sub: "google-oauth2|10233470761",
}
}我想做一个查询,返回上述响应以及嵌套的userAccount文档。我在Stackoverflow上发现了类似的问题,但是他们的解决方案没有任何进展。我在下面尝试过这样做,但是它返回了上面看到的代码块:
Get(Match(Index("account-user_by_sub"), "google-oauth2|10233470761")),
Lambda("X",
Let(
{
accountUserDoc: Get(Var("X")),
userAccountRef: Get(Select(["data", "userAccount"], Var("accountUserDoc")))
},
{
accountUser: Var("accountUserDoc"),
userAccount: Get(Var("userAccountRef"))
}
)
)发布于 2022-03-04 23:48:33
您尝试的查询不起作用:它试图将两个FQL表达式与一个逗号链接在一起,这两个表达式之间没有连接,因此Lambda不接收参数。
不过你离解决方案很近。试试这个:
Let(
{
accountUserDoc: Get(
Match(
Index("account-user_by_sub"),
"google-oauth2|10233470761"
)
),
userAccountDoc: Get(
Select(["data", "userAccount"], Var("accountUserDoc"))
)
},
{
accountUser: Var("accountUserDoc"),
userAccount: Var("userAccountDoc")
}
)基本上,这将初始的Get放在Let中,而不是试图将文档作为参数传递。
由于您正在对userAccount字段中的值调用userAccount,所以在编写所需的结果时不需要再次执行;无论如何,这都会失败,因为Get接受的是引用,而不是文档。
https://stackoverflow.com/questions/71358174
复制相似问题