Firestore python查询抛出值错误:路径`numberfield`未使用剩余值:number

2024-10-02 10:23:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我第一次使用Firestore,我使用的是Python 3.9.5

我已使用以下方法成功地将数据添加到python中的数据库:

        addDoc = db.collection('My-Collection').document()
        addDoc.set(val)

其中val是一个json对象

但是,当我尝试在number-field上查询集合时:

docs = db.collection("Keno-Games").where("game-number", "==", 373).stream()

这是从firestore控制台查询创建者复制的,它确实可以工作,但当我尝试在python代码中使用它时,它就不能工作了。错误是:

Traceback (most recent call last):
  File "/Users/timbolton/Desktop/kenoApi/kenoFirestoreIngest.py", line 21, in <module>
    docs = db.collection("Keno-Games").where("game-number", "==", 373).stream()
  File "/Users/timbolton/Desktop/kenoApi/venv/lib/python3.9/site-packages/google/cloud/firestore_v1/base_collection.py", line 243, in where
    return query.where(field_path, op_string, value)
  File "/Users/timbolton/Desktop/kenoApi/venv/lib/python3.9/site-packages/google/cloud/firestore_v1/base_query.py", line 278, in where
    field_path_module.split_field_path(field_path)  # raises
  File "/Users/timbolton/Desktop/kenoApi/venv/lib/python3.9/site-packages/google/cloud/firestore_v1/field_path.py", line 84, in split_field_path
    for element in _tokenize_field_path(path):
  File "/Users/timbolton/Desktop/kenoApi/venv/lib/python3.9/site-packages/google/cloud/firestore_v1/field_path.py", line 64, in _tokenize_field_path
    raise ValueError("Path {} not consumed, residue: {}".format(path, path[pos:]))
ValueError: Path game-number not consumed, residue: -number

Tags: pathinpynumberfieldvenvlinewhere

热门问题