Skip to content

$geoNear is only valid as the first stage in a pipeline #2493

Closed
@alterEgo123

Description

@alterEgo123

Hello,

Running the following example which uses $geoNear in an aggregation pipeline returns a $geoNear is only valid as the first stage in a pipeline error.

from mongoengine import *


def aggregate():
    connect()

    class BaseClass(Document):
        meta = {'allow_inheritance': True}

    class Aggr(BaseClass):
        name = StringField()
        c = PointField()

    Aggr.drop_collection()

    Aggr(name="X", c=[10.634584, 35.8245029]).save()
    Aggr(name="Y", c=[10.634584, 35.8245029]).save()

    pipeline = [
        {
            "$geoNear": {
                "near": {"type": "Point", "coordinates": [10.634584, 35.8245029]},
                "distanceField": "c",
                "spherical": True,
            }
        }
    ]
    list(Aggr.objects.aggregate(*pipeline))


aggregate()

Using:

mongoengine: 0.17.0
MongoDB server version: 4.4.0

Metadata

Metadata

Assignees

No one assigned

    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