I am working on a python script to connect to mongodb and query a collection.
I want to find the values for key hp that start with cdl. This query successfully runs when I try through mongo shell but through my python script I see the error.
Do I need to have any escape characters ?
./pymongoconn.py
File "./pymongoconn.py", line 20
for response in conn.collection.find({"hp": /^cdl/},{"n":1 ,"hp":1 , "_id":0 , "rsid" :1, "v":1}):
^
SyntaxError: invalid syntax
Below is my query :
for response in conn.collection.find(
{"hp": /^cdl/},
{"n":1 ,"hp":1 , "_id":0 ,"rsid" :1, "v":1}
):
print (response)