Skip to content Skip to sidebar Skip to footer

Mongo Query In Python If I Use Variable As Value

Am trying to find documents from the mongo collection using the following query. db.collection_name.find({'id' : Id}) where Id is the variable am getting as input. But it doesn't w

Solution 1:

Try str();

Id = str(raw_input("enter id"))
cursor = db.collection_name.find({"id" : Id})

Solution 2:

This may help you..in python3 it is working..

Id = raw_input("enter id: ") 
cursor = db.collection_name.find({"id" : Id})
for i in cursor:
    print(i)

there is no require to convert raw_input() to string,Because raw_input() is already get input from user as string..

Post a Comment for "Mongo Query In Python If I Use Variable As Value"