Fab*_*rpo 1 pagination facebook-fql faunadb
我在 faunadb 上创建了一个索引,按时间戳排序,以便首先获取最新的项目,并且我尝试一次检索 100 个项目。我的问题是,当我从结果中输入“after”参数时,我收到与初始查询相同的结果。
这是我创建的索引:
CreateIndex({
name: "all_school_queries",
source: Collection('<school_queries_reversed>'),
values: values: [
{
field: ["ts", {reverse: true}]
},
{
field: ["ref"]
}
]
})
Run Code Online (Sandbox Code Playgroud)
这就是我查询数据库的方式:
Map(
Paginate(Match(Index("school_query_reverse")), {
after: [ Ref(Collection("collection_name") ,'collection ref from first query')],
}),
Lambda(
['ts',"ref"],
Get(Var("ref"))
)
)
Run Code Online (Sandbox Code Playgroud)
这是第一个结果:
{
before: [Ref(Collection("collection_name"), "275484304279077376")],
after: [
1598907150720000,
Ref(Collection("school_queries"), "12345"),
Ref(Collection("school_queries"), "12345")
],
}
Run Code Online (Sandbox Code Playgroud)
我已经使用了之后的时间戳1598907150720000和参考,12345。我首先尝试了控制台以确保可以获得正确的响应,但是在输入之后的任一结果后,我得到了相同的结果。
我会尝试回答你的问题(我是 FaunaDB 的开发顾问)。我不得不说,由于语法对我来说似乎没有意义,我对你的问题感到非常困惑,所以如果这不是你正在寻找的答案,我深表歉意。
令我困惑的事情。
不过没关系,我尝试重现您的问题,因为我不知道数据看起来如何,所以我保持简单。

我使用的索引如下所示:
CreateIndex({
name: "all_school_queries",
source: Collection('school_queries'),
values: [
{
field: ["ts"],
reverse: true
},
{
field: ["ref"]
}
]
})
Run Code Online (Sandbox Code Playgroud)
如果我按如下方式查询该索引:
Map(
Paginate(Match(Index("all_school_queries")), {size: 1}),
Lambda(
['ts',"ref"],
Get(Var("ref"))
)
)
Run Code Online (Sandbox Code Playgroud)
我确实得到了我首先添加的最后一个元素(反向索引)
{
after: [
1599220462170000,
Ref(Collection("school_queries"), "275735235372515847"),
Ref(Collection("school_queries"), "275735235372515847")
],
data: [
{
ref: Ref(Collection("school_queries"), "275735244842205703"),
ts: 1599220471200000,
data: {
query: "bli"
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
当我使用返回的 after 光标获取下一页时(我在这里仅指定了一个元素的页面):
Map(
Paginate(Match(Index("all_school_queries")), {size: 1, after: [
1599220462170000,
Ref(Collection("school_queries"), "275735235372515847"),
Ref(Collection("school_queries"), "275735235372515847")
]}),
Lambda(
['ts',"ref"],
Get(Var("ref"))
)
)
Run Code Online (Sandbox Code Playgroud)
我确实得到了(如预期的)另一个元素。
{
before: [
1599220462170000,
Ref(Collection("school_queries"), "275735235372515847"),
Ref(Collection("school_queries"), "275735235372515847")
],
data: [
{
ref: Ref(Collection("school_queries"), "275735235372515847"),
ts: 1599220462170000,
data: {
query: "bla"
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
这不适合你吗?
| 归档时间: |
|
| 查看次数: |
716 次 |
| 最近记录: |