firebase - 单个属性上的 NeedIndexError (Google AppEngine + Firestore)
问题描述
我有一个已上传到 Google AppEngine 的 Python(标准环境)应用程序,它使用 Firestore 进行存储。
这是我的模型类的简化版本:
from google.appengine.ext import ndb
class User(ndb.Model):
displayName = ndb.StringProperty()
@classmethod
def query_users(cls):
query = cls.query().order(cls.displayName)
db_objects = query.fetch()
# do something with db_objects
这正如我在本地开发服务器(dev_appserver.py)中所期望的那样工作。
当我不使用 .order(cls.displayName) 调用时,我没有收到错误,但显然结果没有排序。
当我使用 .order(cls.displayName) 调用时,我收到以下错误:
NeedIndexError: no matching index found.
The suggested index for this query is:
- kind: User
properties:
- name: displayName
所有(10-15 次测试)用户文档在被查询的 Firestore 实例中都有一个 displayName 属性。我认为 Firestore 为每个属性生成了一个索引?
我发现了一个关于复合索引的稍微相似的问题,但我的问题更多是关于单个属性的索引。
此外,该项目的 Google Cloud Platform (GCP) 控制台中的索引页面不显示任何索引,而是显示以下文本:
To use Firestore during Beta, open the Firebase console.
Firebase 控制台索引页面 ( https://console.firebase.google.com/project/ $PROJECT_ID/database/firestore/indexes ) 没有列出复合索引或其他索引。
我有一个自动生成的 index.yaml 文件,其中包含复杂的索引(并且没有简单的索引)。
我还有一个 firestore.indexes.json 文件,目前没有指定任何内容:
{
"indexes": []
}
(我在 firestore.rules 文件中创建了一些数据库规则,并同时创建了这个文件。)
通过阅读有关索引的 Firestore 文档,firestore.indexes.json 文件应该用于复杂(多属性)索引,而不是用于单属性索引。
那么,Google AppEngine (GAE) / Google Cloud Platform(GCP,Python 标准环境)是否与 Firestore 索引配合得很好?
更重要的是,有人对如何用单一属性索引解决这个问题有任何想法吗?
对于后续问题,将 Firestore 用于数据存储时是否会忽略 index.yaml 文件?我应该在 firestore.indexes.json 文件中的 index.yaml 文件中重新创建索引并部署它吗?
解决方案
推荐阅读
- css - 使用 css 网格显示项目并构建第一个固定列
- javascript - 更新相同键的数组值
- python - 在 apply_async 中更新 db 模型不执行
- google-apps-script - Google 表格 - 夜班时间使用 Arrayformula,周末时间使用 Arrayformula
- create-react-app - 如何将 Jest intellisense 与 create-react-app 和 VScode 一起使用?
- react-native - 如何为不同用户创建单独的导航抽屉:React 导航 v5
- python-2.7 - 皮林特和蟒蛇
运行关于包的相对导入的冲突('没有命名的模块 ' 如果我按照 pylint 方式进行操作,则会出错) - r - 如何使用 R 中其他列的值格式化字符串
- javascript - 为什么我的 D3.csv() 方法返回“未定义”
- bash - 我如何将文件名存储为shell脚本中的变量