firebase 异常,失败前提条件:400找不到匹配的索引

noj0wjuj  于 2022-11-30  发布在  其他
关注(0)|答案(1)|浏览(115)

我需要使用python从google云数据存储中获取数据,当获取所有集合时成功,但当尝试根据键获取特定值时失败,我提供了存储数据方法和获取数据方法:

def store_data(name, value):
    entity = datastore.Entity(key=datastore_client.key('visit', name))
    entity.update({
        'name': name,
        'value': value
    })
    datastore_client.put(entity)

def fetch_name(name):
    query = datastore_client.query(kind='visit')
    print("name is: " + name)
    # query.add_filter("name", "=", name)
    results = list(query.fetch())
    # print("GET - param is results: " + results)
    return jsonify(results)

这意味着,如果我取消提交这行代码:

# query.add_filter("name", "=", name)

将出现以下错误:

Traceback (most recent call last):
  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/flask/app.py", line 2077, in wsgi_app
    response = self.full_dispatch_request()
  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/flask/app.py", line 1525, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/flask/app.py", line 1523, in full_dispatch_request
    rv = self.dispatch_request()
  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/flask/app.py", line 1509, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/srv/main.py", line 107, in getVariable
    times = fetch_times(name)
  File "/srv/main.py", line 40, in fetch_times
    results = list(query.fetch())
  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/google/api_core/page_iterator.py", line 208, in _items_iter
    for page in self._page_iter(increment=False):
  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/google/api_core/page_iterator.py", line 244, in _page_iter
    page = self._next_page()
  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/google/cloud/datastore/query.py", line 610, in _next_page
    response_pb = self.client._datastore_api.run_query(
  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/google/cloud/datastore_v1/services/datastore/client.py", line 579, in run_query
    response = rpc(
  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/google/api_core/gapic_v1/method.py", line 154, in __call__
    return wrapped_func(*args, **kwargs)
  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/google/api_core/retry.py", line 283, in retry_wrapped_func
    return retry_target(
  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/google/api_core/retry.py", line 190, in retry_target
    return target()
  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/google/api_core/grpc_helpers.py", line 74, in error_remapped_callable
    raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.FailedPrecondition: 400 no matching index found.

并且响应返回:内部服务器错误。如何修复?
我试图从谷歌云页面的用户界面添加索引-添加索引到名称属性。

fwzugrvs

fwzugrvs1#

您需要检查数据库的模式(https://cloud.google.com/sdk/gcloud/reference/alpha/firestore/databases/describe)。很可能您的数据库处于Firestore本机模式而不是Datastore模式下的Firestore。如果是这样,您需要使用Firestore客户端库而不是Datastore客户端库,或者将数据库类型切换为Datastore模式。

相关问题