1

I am trying to connect to my Twitter application by fetching the consumer key and access token from a MongoDatabase. I'm relatively new to MongoDB and am still trying to get a handle on things. I need the data as a string, but it's being returned as a cursor. I understand that what I have so far won't be the exact value im looking for, but rather something like

{"value" : "ggggktjjjfr4kf0k04kf0rkforvo"}

but if I could at least get this as a string I could begin to decode it. Any advice would be appreciated.

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
  • Use .find_one() and access the key of the dict returned. i.e consumer_key = collection_Authentication.find_one({"name":"consumer_key"}, {"_id":0, "value":1})["value"] Commented Jul 13, 2017 at 4:42

1 Answer 1

1

Something like:

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

Use find_one to get the document immediately. In Python the document is represented as a dict, so retrieve the string by its field name, "value", using brackets: ["value"].

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.