I am trying to do a simple query based on two conditions in MongoDB using pymongo.
I am using the sample restaurants data set from the tutorial documentation. I have:
from pymongo import MongoClient
import pymongo
import pandas as pd
client = MongoClient()
db = client.test
cursor = db.restaurants.find({"$and":[{'borough':"Manhattan"},{"grades":{'grade':"A"}}]}
for record in cursor:
print record
I am just trying to print all the restaurants in Manhattan with a grade of 'B.' But this pulls back no results. I have also tried
cursor = db.restaurants.find({"borough":"Manhattan", "grades.grade":"B"})
but this will only filter by the first condition and won't filter by the "grade." It's exactly how it is laid out in the documentation but I can't get it to work.