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

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

1 Comment

Just to point that eval is not recommended stackoverflow.com/questions/9383740/what-does-pythons-eval-do

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.