2017-07-13 19 views
0

我想通過從MongoDatabase中提取使用者密鑰和訪問令牌連接到我的Twitter應用程序。我對MongoDB比較陌生,並且仍然試圖處理事情。我需要將數據作爲字符串來使用,但它作爲遊標返回。我的理解是什麼,我至今也不會是精確值即時尋找,而是像轉換MongoDB查找()返回信息字符串與PyMongo

{"value" : "ggggktjjjfr4kf0k04kf0rkforvo"} 

,但如果我至少可以得到這樣一個字符串,我可以開始對其進行解碼。任何意見,將不勝感激。

consumer_key = collection_Authentication.find({"name":"consumer_key"}, {"_id":0, "value":1}) 
consumer_secret=collection_Authentication.find({"name":"consumer_secret"}, {"_id":0, "value":1}) 
access_token = collection_Authentication.find({"name":"access_token"}, {"_id":0, "value":1}) 
access_secret = collection_Authentication.find({"name":"access_secret"}, {"_id":0, "value":1}) 
+0

使用['.find_one()'](http://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.find_one)並訪問字典的關鍵字回。即'consumer_key = collection_Authentication.find_one({「name」:「consumer_key」},{「_id」:0,「value」:1})[「value」]' –

回答

0

喜歡的東西:

consumer_key = collection_Authentication.find_one({"name":"consumer_key"})["value"] 

使用find_one立即獲取文檔。在Python中,該文檔表示爲一個字典,因此通過字段名稱「value」使用括號:["value"]來檢索該字符串。

相關問題