diff --git a/docs/changelog.rst b/docs/changelog.rst index b904a2b8..5898eb1f 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -6,6 +6,7 @@ Changelog Development =========== - (Fill this out as you fix issues and develop your features). +- Bugfix: manually setting SequenceField in DynamicDocument doesn't increment the counter #2471 Changes in 0.22.1 ================= diff --git a/mongoengine/fields.py b/mongoengine/fields.py index 477138a1..cfff2b47 100644 --- a/mongoengine/fields.py +++ b/mongoengine/fields.py @@ -1162,7 +1162,7 @@ class ReferenceField(BaseField): :param document_type: The type of Document that will be referenced :param dbref: Store the reference as :class:`~pymongo.dbref.DBRef` - or as the :class:`~pymongo.objectid.ObjectId`.id . + or as the :class:`~pymongo.objectid.ObjectId`. :param reverse_delete_rule: Determines what to do when the referring object is deleted :param kwargs: Keyword arguments passed into the parent :class:`~mongoengine.BaseField` diff --git a/tests/queryset/test_queryset_aggregation.py b/tests/queryset/test_queryset_aggregation.py index a9c042de..ecc0db6e 100644 --- a/tests/queryset/test_queryset_aggregation.py +++ b/tests/queryset/test_queryset_aggregation.py @@ -248,6 +248,34 @@ class TestQuerysetAggregate(MongoDBTestCase): assert list(data) == [{"_id": p1.pk, "name": "ISABELLA LUANNA"}] + def test_queryset_aggregation_geonear_aggregation_on_pointfield(self): + """test ensures that $geonear can be used as a 1-stage pipeline and that + MongoEngine does not interfer with such pipeline (#2473) + """ + + class Aggr(Document): + name = StringField() + c = PointField() + + Aggr.drop_collection() + + agg1 = Aggr(name="X", c=[10.634584, 35.8245029]).save() + agg2 = Aggr(name="Y", c=[10.634584, 35.8245029]).save() + + pipeline = [ + { + "$geoNear": { + "near": {"type": "Point", "coordinates": [10.634584, 35.8245029]}, + "distanceField": "c", + "spherical": True, + } + } + ] + assert list(Aggr.objects.aggregate(*pipeline)) == [ + {"_id": agg1.id, "c": 0.0, "name": "X"}, + {"_id": agg2.id, "c": 0.0, "name": "Y"}, + ] + if __name__ == "__main__": unittest.main()