Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-54105

$geoNear in $lookup with dynamic coordinates from "parent" collection

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 4.4.3
    • Component/s: None
    • None
    • Query
    • ALL

      Hello,

      I'm trying to get nearest points from joined collection like this:

      db.collectionA.aggregate(
          [
              {
                  $geoNear: {
                  near: { "type": "Point", "coordinates": [-4.4657183, 48.38249] },
                  distanceField: "calcDistance",
                  maxDistance: 10,
                  key: "geometry",
                  includeLocs: "dist.geometry",
                  spherical: "true"
                  }
              },
              {$limit: 100},
              {
                  $lookup: {
                      from: "collectionB",
                      let: {
                          plon: {"$arrayElemAt":["$geometry.coordinates",0]},
                          plat: {"$arrayElemAt":["$geometry.coordinates",1]},
                      },
                      pipeline: [
                          {
                          $geoNear:{
                              "near": {type: "Point", coordinates:
                                  ["$$plon","$$plat"],
                              },
                              key: "geometry",
                              maxDistance: 10000,
                              distanceField: "dist.calculated",
                              spherical: "true"
                          }
                          },
                      ],
                      as: 'joinedGeometry'
                  }
              }
          ]
      )

      So i need for every point in collectionA to find nearest points in the collectionB.

      On the specified aggregation im recieving the following error:

      geo near accepts just one argument when querying for a GeoJSON point. Extra field found: $maxDistance: 10000.0
      

      I tried to remove that field and the following message:

      invalid argument in geo near query: type
      

      I also tried to specify in the let section the numbers like this:

      let: {
          plon: -3.4032917,
          plat: 46.91752,
      }

      But with the same results

       

      Thanks

            Assignee:
            backlog-server-query Backlog - Query Team (Inactive)
            Reporter:
            d.papatsarouchas@gmail.com Dimitris Papatsarouchas
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: