Reputation: 11
I am using pymongo for my project. Everything is working fine. When I find() in my collection, I am getting:
{u'_id': ObjectId('5f08a8f62239f599569dcc6a'), u'value1': u'pizza'}
Instead of this complete field, I just want the value1. My python code is below:
import pymongo
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["db_for_video"]
mycol = mydb["user"]
for x in mycol.find():
print(x)
Can anyone help me in this?
Upvotes: 1
Views: 156
Reputation: 9051
You can use projection
data = mycol.find({}, {'value1': 1, '_id': 0})
for x in data:
print(x)
Output:
{'value1': 'pizza'}
Upvotes: 1