2015-09-02 52 views
0

出於某種原因,使用get()方法時Rethinkdb沒有顯示爲有效對象的字段值:Rethinkdb客戶Python中未顯示字段值

>>> 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'[email protected]'}] 

爲什麼get()不顯示的字段值的任何想法,但filter()呢? user_id是「用戶」表的主鍵。思考?

回答

1

RethinkDB的.get返回單個對象,而不是數組或遊標。由於致電list,您的代碼正在返回一個字段列表:

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