通过数据存储库使用Google Cloud FiRestore时找不到匹配的索引(&Q) [英] "no matching index found" when using Google Cloud Firestore via Datastore library

查看:37
本文介绍了通过数据存储库使用Google Cloud FiRestore时找不到匹配的索引(&Q)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Google Cloud Platform项目,其中的Datastore配置为FiRestore模式,其中以下(Python)代码会产生google.api_core.exceptions.FailedPrecondition: 400 no matching index found.错误。

from google.cloud import datastore

store = datastore.Client(project='my-project')
query = store.query(kind='my-kind')
query.add_filter('start_date', '<', 1500000000)
results = query.fetch()
for r in results:  # error thrown here
    print(r)
由于FiRestore会自动索引单个字段(我并没有将start_timestamp字段排除在此自动索引之外),因此我预计这会起作用。我做错了什么?

(请注意,这在另一个项目上非常有效,其中Datastore处于Datastore模式,而不是FiRestore模式;不幸的是,我需要使用的项目已经安装了FiRestore。由于FiRestore应该与数据存储区向后兼容,因此我曾希望可以正常工作。)

推荐答案

正如Jim Morrison指出的,您需要使用FiRestore库。

from google.cloud import firestore
db = firestore.Client()
# [START get_simple_query]
docs = db.collection(u'my-collection').where(u'start_date', u'<=', 1500000000).stream()

for doc in docs:
    print(u'{} => {}'.format(doc.id, doc.to_dict()))

这篇关于通过数据存储库使用Google Cloud FiRestore时找不到匹配的索引(&Q)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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