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

Support $near and $nearSphere predicates on sharded collections

    • Type: Icon: New Feature New Feature
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.7.1
    • Affects Version/s: None
    • Component/s: Geo, Sharding
    • Labels:
      None
    • Fully Compatible
    • Query 2018-01-01

      Currently, users who wish to execute near queries against sharded collections must use either the geoNear command or the $geoNear aggregation stage. The $near and $nearSphere query predicates, on the other hand, will fail when issued against a sharded collection. We should add support for sharded $near/$nearSphere, especially given future plans to mark the query the geoNear command as deprecated.

      One way to accomplish this would be to make use of the existing "geoNearDistance" $meta projection. In this design, the mongos query path would extend a $near query to project the "geoNearDistance" metadata as teh sort key. The query issued from mongos to the shards would look something like this:

      > db.c.find({a: {$nearSphere: [1, 1]}}, {$sortKey: {$meta: "geoNearDistance"}})
      { "_id" : ObjectId("599c54f2c4ed9620c11bd27b"), "a" : [ 1, 1 ], "$sortKey" : 0 }
      { "_id" : ObjectId("599c577621d4e4bc06f8c498"), "a" : [ 1, 2 ], "$sortKey" : 0.0174532925199433 }
      

      The AsyncResultsMerger, which merges query results on mongos, already knows how to interpret $sortKey in order to do a merge-sort.

            Assignee:
            tess.avitabile@mongodb.com Tess Avitabile (Inactive)
            Reporter:
            mathias@mongodb.com Mathias Stearn
            Votes:
            22 Vote for this issue
            Watchers:
            20 Start watching this issue

              Created:
              Updated:
              Resolved: