Skip to content

Commit 5f2a094

Browse files
WaVEVtimgraham
authored andcommitted
fix pattern lookups on non-string fields
1 parent c3ebfc7 commit 5f2a094

File tree

2 files changed

+1
-5
lines changed

2 files changed

+1
-5
lines changed

django_mongodb/features.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
4141
# tuple index out of range in process_rhs()
4242
"lookup.tests.LookupTests.test_exact_sliced_queryset_limit_one",
4343
"lookup.tests.LookupTests.test_exact_sliced_queryset_limit_one_offset",
44-
# Regex lookup doesn't work on non-string fields.
45-
"lookup.tests.LookupTests.test_regex_non_string",
46-
# Querying ObjectID with string doesn't work.
47-
"lookup.tests.LookupTests.test_lookup_int_as_str",
4844
# MongoDB gives the wrong result of log(number, base) when base is a
4945
# fractional Decimal: https://jira.mongodb.org/browse/SERVER-91223
5046
"db_functions.math.test_log.LogTests.test_decimal",

django_mongodb/query_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ def process_rhs(node, compiler, connection):
4040
def regex_match(field, regex_vals, insensitive=False):
4141
regex = {"$concat": regex_vals} if isinstance(regex_vals, tuple) else regex_vals
4242
options = "i" if insensitive else ""
43-
return {"$regexMatch": {"input": field, "regex": regex, "options": options}}
43+
return {"$regexMatch": {"input": {"$toString": field}, "regex": regex, "options": options}}

0 commit comments

Comments
 (0)