1

我想做这样的事情

 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中可行吗?

4

1 回答 1

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)

希望有帮助。

于 2013-06-10T22:23:43.643 回答