Query regex issue in Pymongo

Using a simple query, where I filter by a specific value and look for text that start with E. The query works within robo 3t but doesn’t in pymongo, I know it’s due to “/^E/” but why is that?
What’s a potential work around :
query = {'$and': [{"status_derived" : "approved"},{"gss_code":"/^E/"}]}

Any suggestions much appreciated :slight_smile:

You have to use the $regex operator. See https://docs.mongodb.com/manual/reference/operator/query/regex/

1 Like