Skip to content

Commit 221a282

Browse files
WaVEVtimgraham
authored andcommitted
remove unnecessary $convert in ObjectIdAutoField $lookup queries
1 parent d12ed39 commit 221a282

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

django_mongodb/fields/auto.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ def get_prep_value(self, value):
3434
def db_type(self, connection):
3535
return "objectId"
3636

37+
def rel_db_type(self, connection):
38+
return "objectId"
39+
3740
def to_python(self, value):
3841
if value is None or isinstance(value, int):
3942
return value

tests/queries_/test_mql.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ def test_join(self):
1818
query,
1919
"db.queries__book.aggregate(["
2020
"{'$lookup': {'from': 'queries__author', "
21-
"'let': {'parent__field__0': {'$convert': {'input': '$author_id', 'to': 'string'}}}, "
22-
"'pipeline': [{'$match': {'$expr': {'$and': [{'$eq': ['$$parent__field__0', "
23-
"{'$convert': {'input': '$_id', 'to': 'string'}}]}]}}}], 'as': 'queries__author'}}, "
21+
"'let': {'parent__field__0': '$author_id'}, "
22+
"'pipeline': [{'$match': {'$expr': "
23+
"{'$and': [{'$eq': ['$$parent__field__0', '$_id']}]}}}], 'as': 'queries__author'}}, "
2424
"{'$unwind': '$queries__author'}, "
2525
"{'$match': {'$expr': {'$eq': ['$queries__author.name', 'Bob']}}}])",
2626
)

0 commit comments

Comments
 (0)