简体   繁体   中英

Pymongo case insensitive regex query over a list

I have a list that I would like to query against using $in in pymongo, but I also need it to be case insensitive for each value in the list. Before I needed the list, my code looked something like this:

query = {'field': {'$regex': 'value', '$options': 'i'}}
for i in col.find(query): print(i)

where col is the pymongo collection.

I tried doing this:

query = {'field': {'$regex': {'$in':['value1', 'value2']}, '$options': 'i'}}
for i in col.find(query): print(i)

but it doesn't seem to work

Just put pipe operator between regex . Try below query. Although I couldn't run this query as there are no sample documents.

query = {'field': {'$regex': 'value1|value2'}, '$options': 'i'}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM