Skip to content

Commit 5858ea1

Browse files
authored
Merge pull request MongoEngine#2478 from bagerard/add_geonear_aggregation_test
Add $geonear aggregation test
2 parents d033e3b + 1f220b4 commit 5858ea1

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Changelog
66
Development
77
===========
88
- (Fill this out as you fix issues and develop your features).
9+
- Bugfix: manually setting SequenceField in DynamicDocument doesn't increment the counter #2471
910

1011
Changes in 0.22.1
1112
=================

mongoengine/fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,7 @@ def __init__(
11621162
11631163
:param document_type: The type of Document that will be referenced
11641164
:param dbref: Store the reference as :class:`~pymongo.dbref.DBRef`
1165-
or as the :class:`~pymongo.objectid.ObjectId`.id .
1165+
or as the :class:`~pymongo.objectid.ObjectId`.
11661166
:param reverse_delete_rule: Determines what to do when the referring
11671167
object is deleted
11681168
:param kwargs: Keyword arguments passed into the parent :class:`~mongoengine.BaseField`

tests/queryset/test_queryset_aggregation.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,34 @@ class Person(Document):
248248

249249
assert list(data) == [{"_id": p1.pk, "name": "ISABELLA LUANNA"}]
250250

251+
def test_queryset_aggregation_geonear_aggregation_on_pointfield(self):
252+
"""test ensures that $geonear can be used as a 1-stage pipeline and that
253+
MongoEngine does not interfer with such pipeline (#2473)
254+
"""
255+
256+
class Aggr(Document):
257+
name = StringField()
258+
c = PointField()
259+
260+
Aggr.drop_collection()
261+
262+
agg1 = Aggr(name="X", c=[10.634584, 35.8245029]).save()
263+
agg2 = Aggr(name="Y", c=[10.634584, 35.8245029]).save()
264+
265+
pipeline = [
266+
{
267+
"$geoNear": {
268+
"near": {"type": "Point", "coordinates": [10.634584, 35.8245029]},
269+
"distanceField": "c",
270+
"spherical": True,
271+
}
272+
}
273+
]
274+
assert list(Aggr.objects.aggregate(*pipeline)) == [
275+
{"_id": agg1.id, "c": 0.0, "name": "X"},
276+
{"_id": agg2.id, "c": 0.0, "name": "Y"},
277+
]
278+
251279

252280
if __name__ == "__main__":
253281
unittest.main()

0 commit comments

Comments
 (0)