Reputation: 1253
I am trying to search a mongodb using pymongo as collection.find({},{"project": "IO80211"})
but the search doesnt seem to work
it seems to list all the rows in that collection,any guidance on why the search is not working?
try:
print("Trying to create tags...")
dbuser = os.environ.get('muser', 'techauto1')
dbpass = os.environ.get('mpwd', 'techpass')
uri = 'mongodb://{dbuser}:{dbpass}@techtechbot.scv.company.com:27017/techautomation'.format(**locals())
client = MongoClient(uri)
db = client.techautomation
collection = db['static_radars']
print ("going to for find..")
#cursor = collection.find({"project:%s"%project})
print(collection)
cursor = collection.find({},{"project": "IO80211"})
print ("going to forloop")
for document in cursor:
print('%s'%document)
except (pymongo.errors.AutoReconnect, e):
print('Warning %s'%e)
Upvotes: 1
Views: 773
Reputation: 11580
The first parameter is the query,
the second one is the projection,
as it says in the docs
So you can remove the first empty parameter and pass the query instead
cursor = collection.find({"project": "IO80211"})
Upvotes: 1