gpt4 book ai didi

firebase - 查询与空字段的比较

转载 作者:IT王子 更新时间:2023-10-29 01:04:32 26 4
gpt4 key购买 nike

我的 Firestore 集合包含带有字符串字段的文档,该字段可以是null

我期望如果我查询:

Collection("products").Where("producedDate", "<", "2018-01-15")

我会得到所有“producedDate”早于“2018-10-15”的产品,包括那些“producedDate”为空的产品。

但实际上我没有得到 null

这是故意的还是错误?

最佳答案

它本来就是这样工作的。 documentation指出:

When a query involves a field with values of mixed types, Cloud Firestore uses a deterministic ordering based on the internal representations. The following list shows the order:

  1. Null values
  2. Boolean values
  3. Integer and floating-point values, sorted in numerical order
  4. Date values
  5. Text string values
  6. [...]

请注意,只有当您使用混合类型的值运行查询时,它才会遵循此顺序。在您的查询中,您传递了一个 Date 值,这意味着它只会查询 values of Date type而不是其他人(例如 null)。

为了获得 null 值,您可以通过添加第二个 Where 来创建复合查询:

Collection("products").Where("producedDate", "<", "2018-01-15").Where("producedDate", "==", null)

关于firebase - 查询与空字段的比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48270139/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com