Reputation: 165
I am working in python with pymongo. I have a query in psql that looks like this :
cursor.execute("select id13 from nc_durhamallwithorder where date2 >='2010-01-01' and date2<='2011-01-01'"),
Now i want to convert that query in mongodb type. I did something like this
cursor=mycol1.find({"$and": [ { "date2": { "$gte": "2010-01-01" } }, { "date2": { "$lte":"2011-01-01" } } ] } )
This works fine but i want to select only id13
I thought something like this:
cursor=mycol1.find({"id13":1},{"$and": [ { "date2": { "$gte": "2010-01-01" } }, { "date2": { "$lte":"2011-01-01" } } ] } )
But it doesnt work.Can someone help me?
Upvotes: 0
Views: 128
Reputation: 2484
You can use pass a second argument with a dict and the fields you want to keep
mycol1.find({"$and": [
{ "date2": { "$gte": "2010-01-01" } },
{ "date2": { "$lte":"2011-01-01" } }
]},
{"id13":1}
)
Upvotes: 1