From 221a2826312210928d1adcc5417ac87391b98910 Mon Sep 17 00:00:00 2001 From: Emanuel Lupi Date: Sat, 26 Oct 2024 17:07:13 -0300 Subject: [PATCH] remove unnecessary $convert in ObjectIdAutoField $lookup queries --- django_mongodb/fields/auto.py | 3 +++ tests/queries_/test_mql.py | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/django_mongodb/fields/auto.py b/django_mongodb/fields/auto.py index 34dc3a44..9240c759 100644 --- a/django_mongodb/fields/auto.py +++ b/django_mongodb/fields/auto.py @@ -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 diff --git a/tests/queries_/test_mql.py b/tests/queries_/test_mql.py index 788354c7..d61e5839 100644 --- a/tests/queries_/test_mql.py +++ b/tests/queries_/test_mql.py @@ -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']}}}])", )