I am new to mongoDB and don't know more than the basics of python and i'm trying to get some data from a MongoDB database, I can get it using this code. My question is: How can I convert what comes out (I added it here) to json so that I can separate things like name, brithdate, birthday, etc.
import pymongo
myclient = pymongo.MongoClient("mongodb://10.0.0.45:27017/")
mydb = myclient["mydatabase"]
mycol = mydb["birthdays"]
myquery = { "name": "John" }
mydoc = mycol.find(myquery)
for x in mydoc:
print(x)
This is what gets printed in the for x in mydoc:
data that I get from MongoDB: {u'birthmonth': u'<month>', u'_id': ObjectId('5db3a42431f86884b0746c3e'), u'name': u'<name>', u'birthday': u'<day>', u'birthyear': u'<year>'}
And when I just print mydoc I get
<pymongo.cursor.Cursor object at 0x10a1b4c90>
I am not actually getting the <> in the for x in mydoc:
when I print, I just added them to replace the actual data.
btw I got the code from https://www.w3schools.com/python/python_mongodb_query.asp