来自动物区系数据库的反向数据

问题描述 投票:0回答:1

我一直在查看FQL和Fauna DB的docs索引。有没有一种方法可以反转查询返回的数据的顺序?

这是我的代码:

q.Map(
  q.Paginate(q.Match(q.Index("all_pages")), {
    //! Find way to change order
    size: 3
  }),
  ref => q.Get(ref)
)

docs提及reverse标志。

有人知道如何使用它吗?

javascript reactjs facebook-fql next.js faunadb
1个回答
0
投票

想象一下,您有一个包含带有价格字段的文档的集合,我们称它为... ermm ... priceables!

让我们将两个文档的价格分别为1和2。

[{
  "price": 1
},
{
  "price": 2
}]

Image in UI console of the documents

创建常规索引

然后使用以下代码段在该价格值上创建常规范围指数:

CreateIndex({
  name: "regular-value-index",
  unique: false,
  serialized: true,
  source: Collection("priceables"),
  terms: [],
  values: [
    {
      field: ["data", "price"]
    }
  ]
})

创建反向索引

可以有多个值(例如,复合索引),并且可以为每个值设置反向字段。若要创建反向索引,请将该特定值的反向设置为true。

CreateIndex({
  name: "reverse-value-index",
  unique: false,
  serialized: true,
  source: Collection("priceables"),
  terms: [],
  values: [
    {
      field: ["data", "price"],
      reverse: true
    }
  ]
})

如果进入UI控制台并打开索引,您会注意到这些值从最高到最低排序。UI console, reverse index

我想让您感到困惑的是,您还不能在用户界面中设置反向布尔值。但是您只需转到Shell并粘贴FQL代码以创建索引:Image of the shell

© www.soinside.com 2019 - 2024. All rights reserved.