微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 FaunaDB 的文档中索引作为 @relation 的值?

如何解决如何在 FaunaDB 的文档中索引作为 @relation 的值?

是否可以从 FaunaDB 中的 @relation 类型创建值的索引?这是架构,但我无法弄清楚如何为 data.testing.status 值创建索引。

type TestType {
  testing: Testing!
}

type Testing {
  status: PaymentStatus!
  testType: [TestType!] @relation
}

enum PaymentStatus {
  PAID
  UNPAID
}

我不知道枚举是否导致问题?我找不到任何关于此的文档。

这是查询

Map(
  Paginate(Match(Index("certificate_remittance_by_remittance"),"UNPAID")),Lambda("ref",Get(Var("ref")))
)

以及相关文档数据:

 "ref": Ref(Collection("Certificate"),"302119834927235593"),"ts": 1624382777140000,"data": {
    "remittance": Ref(Collection("Remittance"),"302119834830766601"),}

及汇款凭证:

{
  "ref": Ref(Collection("Remittance"),"data": {
    "status": "UNPAID","chequeNumber": "","remittanceOwed": 245,"remittanceAmount": 245
  }
}

解决方法

当然可以。

架构的 enum 部分不会导致问题。如果是这样,您将无法成功导入架构。

使用您提供的架构,请注意 GraphQL API 已经为您创建了关系索引:

Get(Index("testType_testing_by_testing"))

{
  ref: Index("testType_testing_by_testing"),ts: 1624315929200000,active: true,serialized: true,name: "testType_testing_by_testing",source: Collection("TestType"),data: {
    gql: {
      ts: Time("2021-06-21T22:52:08.969203Z")
    }
  },terms: [
    {
      field: ["data","testing"]
    }
  ],unique: false,partitions: 1
}

要为 TestType 集合添加索引,请在 status 字段上运行:

CreateIndex({
  name: "TestType_by_status",terms: [
    { field: ["data","status"] },]
})

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。