【问题标题】:What is the JSON format for a firestore individual field index within a collection group query?集合组查询中的 Firestore 单个字段索引的 JSON 格式是什么?
【发布时间】:2019-10-19 01:57:12
【问题描述】:

我们现在可以从一个很棒的集合组中检索文档。为此,我需要通过 Firebase 控制台上的错误消息创建索引。如何将此新索引添加到 firestore.indexes.json 文件?

documentation 的示例:

let museums = db.collectionGroup('landmarks').where('type', '==', 'museum');
museums.get().then(function(querySnapshot) {
  querySnapshot.forEach(function(doc) {
    console.log(doc.id, ' => ', doc.data());
  });
});

【问题讨论】:

  • 如果您通过firebase控制台添加,如果您使用cli工具,它将自动与您的项目同步
  • 有趣的@DougStevenson 我总是问他们怎么会出现在我的项目中
  • 这仅在您第一次使用 firebase init 时有效。之后,就没有同步了。
  • 你去...你知道更多,谢谢@DougStevenson

标签: firebase google-cloud-firestore firebase-cli


【解决方案1】:

在您的索引文件的顶层,添加一个名为 fieldOverrides 的新元素并像这样填充它:

{
  "fieldOverrides": [
    {
      "collectionGroup": "landmarks",
      "fieldPath": "type",
      "indexes": [
        {
          "order": "ASCENDING",
          "queryScope": "COLLECTION"
        },
        {
          "order": "DESCENDING",
          "queryScope": "COLLECTION"
        },
        {
          "arrayConfig": "CONTAINS",
          "queryScope": "COLLECTION"
        },
        {
          "order": "ASCENDING",
          "queryScope": "COLLECTION_GROUP"
        }
      ]
    }
  ]
}

这会在COLLECTION 范围内为landmarks 中的type 字段保留所有默认自动索引,并允许在type 范围内使用type

【讨论】:

  • 谢谢@DougStevenson!
  • 如果你觉得这个答案有帮助,请接受它是正确的。
猜你喜欢
  • 2019-04-03
  • 2020-12-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-16
  • 1970-01-01
  • 1970-01-01
  • 2019-10-02
相关资源
最近更新 更多