Skip to content

Count() in QuerySet.annotate() crashes: Unknown expression $count #79

@timgraham

Description

@timgraham

QuerySet: Author.objects.annotate(c=Count("id"))

SQL:

SELECT "annotations_author"."id",
       "annotations_author"."name",
       "annotations_author"."age",
       COUNT("annotations_author"."id") AS "c"
FROM "annotations_author"
GROUP BY "annotations_author"."id",
         "annotations_author"."name",
         "annotations_author"."age"

MQL:
{'$project': {'_id': 1, 'name': 1, 'age': 1, 'c': {'$count': ['$_id']}}}
Error:
pymongo.errors.OperationFailure: Invalid $project :: caused by :: Unknown expression $count,

If the query can't be expressed correctly, django-mongodb should raise a helpful NotSupportedError, and the limitation should be documented in the README.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions