Вы можете использовать оператор запроса $ regex и указать регистронезависимую опцию "i".
На основе этих тестовых документов:
{'ip': '10.2.7.98',
'other': 'another field',
'partition': 'this is coMMon',
'pools': 'test doc 1'}
{'ip': '7.98.202.101',
'other': 'another field',
'partition': 'Common partition',
'pools': 'test doc 2'}
{'ip': '7.9.202.101',
'other': 'another field',
'partition': 'Cmmon partition',
'pools': 'test doc 3'}
{'ip': '7.7.98.122',
'other': 'another field',
'partition': 'Como partition',
'pools': 'test doc 4'}
Следующий синтаксис pymon go должен давать желаемые результаты (просто для удобства обработайте курсор как список). Поскольку $and
является значением по умолчанию, в этом нет необходимости.
ip_value = '7.98'
partition_value = 'common'
ip_filter = {'ip': {'$regex': ip_value, "$options": "i"}}
partition_filter = {'partition': {'$regex': partition_value, "$options": "i"}}
query = {}
query.update(ip_filter)
query.update(partition_filter)
projection = {'_id': False}
mlist1 = list(coll.find(query, projection))
for mdoc in mlist1:
pprint.pprint(mdoc)
Результатом является выбор следующих 2 документов:
{'ip': '10.2.7.98',
'other': 'another field',
'partition': 'this is coMMon',
'pools': 'test doc 1'}
{'ip': '7.98.202.101',
'other': 'another field',
'partition': 'Common partition',
'pools': 'test doc 2'}