Skip to content

Commit 2d6c0b5

Browse files
committed
Add support for JSONArray function
1 parent c23f15e commit 2d6c0b5

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

django_mongodb_backend/features.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
8787
# of $setIsSubset must be arrays. Second argument is of type: null"
8888
# https://jira.mongodb.org/browse/SERVER-99186
8989
"model_fields_.test_arrayfield.QueryingTests.test_contained_by_subquery",
90-
# JSONArray not implemented.
91-
"db_functions.json.test_json_array.JSONArrayTests",
9290
# Some usage of prefetch_related() raises "ColPairs is not supported."
9391
"known_related_objects.tests.ExistingRelatedInstancesTests.test_one_to_one_multi_prefetch_related",
9492
"known_related_objects.tests.ExistingRelatedInstancesTests.test_one_to_one_prefetch_related",

django_mongodb_backend/functions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from django.db import NotSupportedError
22
from django.db.models.expressions import Func
3+
from django.db.models.functions import JSONArray
34
from django.db.models.functions.comparison import Cast, Coalesce, Greatest, Least, NullIf
45
from django.db.models.functions.datetime import (
56
Extract,
@@ -106,6 +107,10 @@ def func(self, compiler, connection):
106107
return {f"${operator}": lhs_mql}
107108

108109

110+
def json_array(self, compiler, connection, **extra_context): # noqa: ARG001
111+
return process_lhs(self, compiler, connection)
112+
113+
109114
def left(self, compiler, connection):
110115
return self.get_substr().as_mql(compiler, connection)
111116

@@ -238,6 +243,7 @@ def register_functions():
238243
Cot.as_mql = cot
239244
Extract.as_mql = extract
240245
Func.as_mql = func
246+
JSONArray.as_mql = json_array
241247
Left.as_mql = left
242248
Length.as_mql = length
243249
Log.as_mql = log

0 commit comments

Comments
 (0)