1

I would like to do something like this

 contents = contents.find() # get all from collection
if user filled search box 1:
     contents = contents.find({'field1':seached_var})
if user filled search box 2:
     contents = contents.find({'field2':seached_var2})

contents would contain the final filtered result. Is it doable in python with mongodb?

1 Answer 1

1

How about doing it this way:

conditions = {}
if user filled search box 1:
     conditions['field1'] = seached_var
if user filled search box 2:
     conditions['field2'] = seached_var2

contents = contents.find(conditions)

Hope that helps.

Sign up to request clarification or add additional context in comments.

Comments

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.