2011-10-26 2 views
0

나는 모든 레코드를 선택합니다으로 $ 또는 절을 작성하는 방법을 그 제목은 키워드를 포함하거나 위치가 키워드가 포함되어 있는지 여부 : 이것은 $와 절을 찾을 것입니다MongoDB를 : RE

name_regex = ".*" + keyword + ".*"; 
name_reg = re.compile(name_regex,re.IGNORECASE) 
search_dict["title"] = name_reg 
search_dict["location"] = name_reg 
records = collection.find(search_dict) 

합니다. $ 또는 절을 지정하는 방법?

답변

1

의 pymongo에 해당 :

db.collection.find({$or:[{title:name_reg}, {location:name_reg}]})