Skip to content

Commit

Permalink
remove unnecessary $convert in ObjectIdAutoField $lookup queries
Browse files Browse the repository at this point in the history
  • Loading branch information
WaVEV authored and timgraham committed Oct 28, 2024
1 parent d12ed39 commit 221a282
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions django_mongodb/fields/auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def get_prep_value(self, value):
def db_type(self, connection):
return "objectId"

def rel_db_type(self, connection):
return "objectId"

def to_python(self, value):
if value is None or isinstance(value, int):
return value
Expand Down
6 changes: 3 additions & 3 deletions tests/queries_/test_mql.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def test_join(self):
query,
"db.queries__book.aggregate(["
"{'$lookup': {'from': 'queries__author', "
"'let': {'parent__field__0': {'$convert': {'input': '$author_id', 'to': 'string'}}}, "
"'pipeline': [{'$match': {'$expr': {'$and': [{'$eq': ['$$parent__field__0', "
"{'$convert': {'input': '$_id', 'to': 'string'}}]}]}}}], 'as': 'queries__author'}}, "
"'let': {'parent__field__0': '$author_id'}, "
"'pipeline': [{'$match': {'$expr': "
"{'$and': [{'$eq': ['$$parent__field__0', '$_id']}]}}}], 'as': 'queries__author'}}, "
"{'$unwind': '$queries__author'}, "
"{'$match': {'$expr': {'$eq': ['$queries__author.name', 'Bob']}}}])",
)

0 comments on commit 221a282

Please sign in to comment.