【问题标题】:Firebase query where not all the documents contain requested fieldFirebase 查询并非所有文档都包含请求的字段
【发布时间】:2023-03-29 02:09:01
【问题描述】:

我在我的项目中使用 firebase。 现在我正在尝试从firebase获取文件,但面临以下问题。 基本上我有没有hidden 字段的旧文档和有它的新文档。现在我想获取hidden == fasle 所在的每个文档,而我正在尝试的是以下内容

getUserDocuments(): Observable<DocumentInterface[]> {
return this.db
  .collection<DocumentInterface>(CollectionNames.DOCUMENTS, (ref) =>
    ref.where('uid', '==', this.uid).orderBy('timeCreated', 'desc').where('hidden', '==', 'false')
  )
  .valueChanges();
}

我已经仔细阅读了文档,但我不明白为什么我会收到空​​数组。任何帮助将不胜感激!

【问题讨论】:

  • 添加你的firestore
  • @PeterHaddad 你是什么意思?
  • 您能否添加与上述查询相关的 Firestore 集合的屏幕截图?
  • 所有文档都有timeCreated字段吗?

标签: typescript firebase google-cloud-firestore angularfire2


【解决方案1】:

我发现了问题。在.where('hidden', '==', 'false') 中,我传递了值为false 的字符串,但在数据库中它是布尔值,因此通过删除引号解决了问题:.where('hidden', '==', false)

【讨论】:

  • 很高兴听到您找到了解决方案。请考虑接受您自己的答案,以便有类似问题的社区可以查看您的解决方案:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-29
  • 2020-05-26
  • 1970-01-01
  • 1970-01-01
  • 2019-03-24
  • 1970-01-01
相关资源
最近更新 更多