【问题标题】:Firestore get where predicate?Firestore 在哪里获取谓词?
【发布时间】:2018-12-05 04:04:53
【问题描述】:

我有一个 firestore 集合,其中每个文档都有一个字符串“tags”的集合,我想对 firestore 集合进行查询并获取字符串出现在 tags 数组中的所有结果。

类似:

 var { docs } = await admin
            .firestore()
            .collection('submissions')
            .where((x)=> x.tags.contains('mytag'))
            .get();

这可能吗?

【问题讨论】:

标签: javascript firebase google-cloud-firestore


【解决方案1】:

您不能(还)查询数组包含特定值的项目。请参阅Firestore documentation on working with arrays, lists, and sets,它建议您将标签建模为:

tags: {
  mytag: true,
  myothertag: true
}

然后查询它:

db.collection('submissions')
    .where('tags.mytag', '==', true)
    .get()
    .then(() => {
        // ...
    });
)

我还建议您阅读我对Firebase query if child of child contains a value 的回答,其中包含另一个示例。虽然它适用于 Firebase 实时数据库,但此处也适用相同的逻辑。

正在做一些工作,以允许像您一样查询数组中的值。但像往常一样:没有承诺何时可用,因此请留意 release notes 以获取 Firestore 更新。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-12
    • 2014-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多