doufu6130 2018-01-15 20:21
浏览 28
已采纳

查询比较为空字段

My Firestore collection has documents with a string field, which can be null.

I was expecting that if I query:

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

I would get all products whose "producedDate" is earlier than "2018-10-15", including those whose "producedDate" is null.

But actually I am not getting the nulls.

Is this intended or it's a bug?

  • 写回答

1条回答 默认 最新

  • dthjnc306679 2018-01-15 23:07
    关注

    It was intended to work that way. The documentation states that:

    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. [...]

    Note that it only follows this order when you're running a query with values of mixed types. In your query you're passing a Date value, which means it will only query on values of Date type and not the others (like null for example).

    In order to get the null values, you can create a compound query, by adding a second Where:

    Collection("products").Where("producedDate", "<", "2018-01-15").Where("producedDate", "==", null)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器