1

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

NIKHIL RANE
  • 4,012
  • 2
  • 22
  • 45

1 Answers1

1

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)
NIKHIL RANE
  • 4,012
  • 2
  • 22
  • 45
  • Just to point that eval is not recommended https://stackoverflow.com/questions/9383740/what-does-pythons-eval-do – Jaziel_Inc Aug 17 '18 at 20:48