Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-11206

Docs for SERVER-1981: Support $near and $nearSphere predicates on sharded collections

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.7.1
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      The $near and $nearSphere query operators are now supported on sharded collections.

      Scope of work

      $near
      $nearSphere
      geospatial-queries

      Engineering Ticket Description:

      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:
            kay.kim@mongodb.com Kay Kim (Inactive)
            Reporter:
            kay.kim@mongodb.com Kay Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              6 years, 3 days ago