使用Python API,我在“ spells”集合中创建了一个文档,如下所示:
>>> client.query(
... q.create(
... q.collection("spells"),
... {
... "data": {"name": "Mountainous Thunder", "element": "air", "cost": 15}
... }
... ))
{'ref': Ref(id=243802653698556416, collection=Ref(id=spells, collection=Ref(id=collections))), 'ts': 1568767179200000, 'data': {'name': 'Mountainous Thunder', 'element': 'air', 'cost': 15}}
然后,我尝试按以下方式获取带有ts的文档:
>>> client.query(q.get(q.ref(q.collection("spells", "1568767179200000"))))
但是,结果是,错误为“期望提供参考,提供了对象”。
>>> client.query(q.get(q.ref(q.collection("spells", "1568767179200000"))))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/dist-packages/faunadb/client.py", line 175, in query
return self._execute("POST", "", _wrap(expression), with_txn_time=True)
File "/usr/local/lib/python3.6/dist-packages/faunadb/client.py", line 242, in _execute
FaunaError.raise_for_status_code(request_result)
File "/usr/local/lib/python3.6/dist-packages/faunadb/errors.py", line 28, in raise_for_status_code
raise BadRequest(request_result)
faunadb.errors.BadRequest: Ref expected, Object provided.
我不知道出了什么问题,欢迎提出任何建议!
答案 0 :(得分:1)
我自己解决了这个问题。我也错过了q.ref的参数。
正确的参数如下:
>>> client.query(q.get(q.ref(q.collection("spells"),"243802585534824962")))
{'ref': Ref(id=243802585534824962, collection=Ref(id=spells, collection=Ref(id=collections))), 'ts': 1568767114140000, 'data': {'name': 'Mountainous Thunder', 'element': 'air', 'cost': 15}}