集合组查询中的firestore单个字段索引的JSON格式是什么? [英] What is the JSON format for a firestore individual field index within a collection group query?

查看:51
本文介绍了集合组查询中的firestore单个字段索引的JSON格式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

We can now retrieve documents from a collection group which is great. To do so, I need to create an index through an error message on the Firebase console. How can I add this new index to the firestore.indexes.json file?

文档的示例:

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

推荐答案

在索引文件的顶层,添加一个名为 fieldOverrides 的新元素,并按如下所示进行填充:

At the top level of your index file, add a new element called fieldOverrides and populate it like this:

{
  "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也可以在 COLLECTION_GROUP 范围内使用.

This preserves the all the default automatic indexing for the type field in landmarks at the COLLECTION scope, and allows for type also to be used at the COLLECTION_GROUP scope.

这篇关于集合组查询中的firestore单个字段索引的JSON格式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆