Boolean operators in mongodb queries using python

I am trying to query my mongo db for an element in python2.7 using

output = collection.find_one({ $and : [{'name' : data['name']},{'phone_1' : data['phone_1']}]})

when i try to run python script tell me

File "./test.py", line 113
output = collection.find_one({ $and : [{'name' : data['name']},{'phone_1' : data['phone_1']}]})
                               ^
SyntaxError: invalid syntax

I checked the manual and version of mongo. I installed mongodb 2.0.6, so the syntax above should be fine. Did I miss something?

+4
source share
1 answer

Just type it in quotation marks:

output = collection.find_one({
    '$and': [
        {'name': data['name']},
        {'phone_1': data['phone_1']}
    ]
})
+6
source

All Articles