问题描述
我在FaunaDB上遇到问题。我是新手,浏览过文档,但是没有运气。我将立即向您展示代码,但SO抱怨我的问题中的代码太多了。
我正在尝试使用FQL执行以下sql语句:
SELECT * FROM order
WHERE cid = '1234'
AND fulfilled = false
AND rank >= 0
AND rank <= 100
我尝试了以下操作:
q.Paginate(
q.Intersection(
q.Match(
q.Index('order_by_cid'),'1234',),q.Match(
q.Index('order_by_status'),false,q.Range(
q.Match('order_by_rank'),[0],[100]
),)
)
但这返回{ data: [] }
我的索引:
{
ref: Index("order_by_cid"),ts: 1602095185756000,active: true,serialized: true,name: "order_by_cid",source: Collection("order"),terms: [{ field: ["data","cid"] }],partitions: 1
}
{
ref: Index("order_by_status"),ts: 1602163027885000,name: "order_by_status","fulfilled"] }],partitions: 1
}
{
ref: Index("order_by_rank"),ts: 1602611790710000,name: "order_by_rank",values: [{ field: ["data","rank"] },{ field: "ref" }],partitions: 8
}
解决方法
索引应为:
CreateIndex(
{
name:'refByCidFulfilled',source:Collection("order"),terms:[{field:['data','cid']},{field:['data','fulfilled']}],values:[{field:['data','rank']},{field:['ref']}]
}
)
您可以查询
Map(
Paginate(
Range(
Match('refByCidFulfilled',[1234,false]),[1],[100])),Lambda(['rank','ref'],Get(Var('ref')
)
)
)