@ qiao правильный, синтаксис $or
правильный, вот полный пример:
import re
from pymongo import Connection
connection = Connection()
db = connection.test_database
db.regex_test.drop()
# Create some sample docs
db.regex_test.save({"user_name": "Rozza", "text": "Writing an example for Bin Chen based on qiao's answer"})
db.regex_test.save({"user_name": "qiao", "text": "Answering Bin Chen's question"})
db.regex_test.save({"user_name": "Bin Chen", "text": "Reading rozza's answer"})
# Do a regex $or query simple example
search_dict = {"$or": [
{"user_name": {"$regex": "^Rozza"}},
{"text": {"$regex": "rozza"}}
]}
assert db.regex_test.find(search_dict).count() == 2
# Do a regex $or query with re.compile
search_dict = {"$or": [
{"user_name": re.compile("*.Rozza.*", re.IGNORECASE)},
{"text": re.compile("*.Rozza.*", re.IGNORECASE)}
]}
assert db.regex_test.find(search_dict).count() == 2