我想做这样的事情
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})
内容将包含最终过滤结果。 用mongodb在python中可行吗?
答案 0 :(得分:1)
这样做怎么样:
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)
希望有所帮助。