Python中的db Client不显示字段值

2024-05-18 05:52:00 发布

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

由于某些原因,在使用get()方法时,db没有显示有效对象的字段值:

>>> import rethinkdb as r
>>> conn = r.connect( "localhost", 28015)
>>> conn.repl()
<rethinkdb.net.DefaultConnection object at 0x7efd3eab8910>
>>> list(r.db('mydb').table('users').get('4339fe22-7686-4105-9fe7-976871fe552a').run())
[u'group_ids', u'user_id', u'name', u'user_type', u'phone', u'email', u'description']

当我使用filter()方法运行相同的查询时,一切都正常工作:

>>> list(r.db('mydb').table('users').filter(lambda u: u['user_id'] == '4339fe22-7686-4105-9fe7-976871fe552a').run())
[{u'group_ids': [u'a75f9f5a-d5a9-4c2b-8e75-1d1bba5de63e'], u'user_id': u'4339fe22-7686-4105-9fe7-976871fe552a', u'name': u'John', u'user_type': u'company admin', u'phone': u'(...) ...-....', u'email': u'john@example.com'}]

为什么get()不显示字段值,而filter()显示字段值user_id是“users”表的主键。有什么想法


Tags: 方法runiddbgettablegroupfilter
1条回答
网友
1楼 · 发布于 2024-05-18 05:52:00

referencedb的.get返回单个对象,而不是数组或游标。由于对list的调用,您的代码正在返回字段列表:

>>> list({'name': 'John', 'user_type': 'company admin'})
['name', 'user_type']

相关问题 更多 >