Reputation: 2681
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?
Upvotes: 1
Views: 885
Reputation: 474281
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.
Upvotes: 1