执行简单查询的cloudfirestorepython总是返回query obj

2024-10-02 00:36:44 发布

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

我知道这个问题听起来可能很傻,但是如何使用Firebase管理SDK(cloudfirestore)和Python正确地查询数据呢?在

是的,我读过这里的文件:

我的数据库:

Database

我的代码:

existing_post = db.collection(u'posts').where(u'id', u'==', u'BpzIbkqAkk0').get()
print(existing_post)

我还尝试省略.get()方法,但每次都得到相同的结果。在

我得到的只是

^{pr2}$

有什么想法吗?在


Tags: and文件数据cloudgetsdksimplepost
2条回答

@Gerardo的评论让我找到了正确的方向。工作代码如下:

existing_posts = db.collection(u'posts').where(u'id', u'==', u'BpzIbkqAkk0').get()
for post in existing_posts:
    print(u'{} => {}'.format(post.id, post.to_dict()))

必须使用to_dict()将生成器对象转换为字典格式。 然后你就可以很容易地访问你想要的任何值。在

existing_posts = db.collection(u'posts').document(u'id').get()
result=existing_posts.to_dict()
id='BpzIbkqAkk0'
result_id=result[id]

试试这个可能对你有帮助。在

相关问题 更多 >

    热门问题