Mehdi Khlifi
Mehdi Khlifi

Reputation: 415

Use $in operator to match regex in mongoengine

Following the MongoDB documentation, you can use the $in operator with a regular expression like wise db.inventory.find( { tags: { $in: [ /^be/, /^st/ ] } } ). Is there a way to achieve the same result using mongoengine?

For example pass {"tags__in": ["/^be/", "/^st/"]} to my query?

Upvotes: 1

Views: 366

Answers (1)

bagerard
bagerard

Reputation: 6374

I don't think this is supported by MongoEngine in normal query construct (i.e I doubt that Doc.objects(tags__in=["/^be/", "/^st/"] will work)) but there is support for __raw__ query (https://docs.mongoengine.org/guide/querying.html#raw-queries)

so the following should work

Inventory.objects(__raw__={"tags": { "$in":["/^be/", "/^st/"]}})

Upvotes: 1

Related Questions