一部の MySQL を mongodb に変換する必要があります。1 つの列に複数の正規表現が一致する MySQL クエリがあります。mongodbで同じことをすることは可能ですか?
SELECT * FROM table WHERE column1 REGEXP r1 AND column1 REGEXP r2 AND colum1 REGEXP r3;
pymongo を使用すると、次のように単一の正規表現で正規表現検索を実行できます。
regex1 = re.compile(r1)
db.collection.find({"column1":regex1})
また
db.collection.find({"column1":{"$regex":"r1"}})
column1 に複数の正規表現を追加するにはどうすればよいですか?
これらは機能しません:
{"column1":regex1,"column1":regex2}
{"column1":{"$regex":"r1","$regex":"r2"}}
{"column1":[regex1,regex2]}
{"column1":{"$regex":["r1","r2"]}}