【问题标题】:How do I index a value which is a @relation in a document in FaunaDB?如何索引 FaunaDB 文档中的 @relation 值?
【发布时间】:2021-09-05 13:51:16
【问题描述】:

是否可以从 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"), "302119834830766601"),
  "ts": 1624382777140000,
  "data": {
    "status": "UNPAID",
    "chequeNumber": "",
    "remittanceOwed": 245,
    "remittanceAmount": 245
  }
}

【问题讨论】:

    标签: faunadb


    【解决方案1】:

    当然。

    架构的 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",
      source: Collection("TestType"),
      terms: [
        { field: ["data", "status"] },
      ]
    })
    

    【讨论】:

    • 谢谢。创建了一个索引,但它没有生成任何文档。当我使用索引上的 Fauna Dashboard 查询字符串“UNPAID”或“PAID”时,它不会返回任何结果。
    • 你能告诉我你正在使用的查询,以及应该匹配的文档之一吗?
    • 感谢您提供更多信息,但文档数据似乎与您的 GraphQL 架构无关?如果您需要 FQL 方面的帮助,最好提出一个新问题。
    猜你喜欢
    • 1970-01-01
    • 2020-06-21
    • 2021-04-07
    • 2020-07-21
    • 2021-11-06
    • 2020-10-29
    • 2020-08-12
    • 2019-03-08
    • 2010-12-27
    相关资源
    最近更新 更多