转换MongoDB Find()使用PyMongo

时间:2017-07-13 04:37:55

标签: mongodb pymongo

我试图通过从MongoDatabase获取使用者密钥和访问令牌来连接到我的Twitter应用程序。我对MongoDB比较陌生,我仍然试图处理好事情。我需要将数据作为字符串,但它作为游标返回。我明白到目前为止我所拥有的并不是我想要的确切价值,而是像

这样的东西
{"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})

1 个答案:

答案 0 :(得分:1)

类似的东西:

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

使用find_one立即获取文档。在Python中,文档表示为dict,因此使用括号["value"]按字段名称" value"检索字符串。