NIKHIL RANE
NIKHIL RANE

Reputation: 4092

Run string command in pymongo

I have following string command

query = "{},{'_id': False}"

Now I want to run above command in following code

client = MongoClient('mongodb://'+host+':'+port+'/')
db_col = database.split(',')
database, collection = db_col[0].strip(), db_col[1].strip()
collection = client[database][collection]
collection = collection.find(query).limit(10)

Is there any solution for that

Upvotes: 1

Views: 826

Answers (1)

NIKHIL RANE
NIKHIL RANE

Reputation: 4092

I found a solution for above question

I'm convert full query in string and use python eval function to execute on python server.

See following code

This is my string query

query = "collection.find({},{'_id': False}).limit(10)"

That is how I done in python

collection_cursor = eval(query)

Upvotes: 1

Related Questions