Skip to content

Commit 97c99ca

Browse files
committed
Add test case for #2473
1 parent af3d3b7 commit 97c99ca

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

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)