[DOCS-11206] Docs for SERVER-1981: Support $near and $nearSphere predicates on sharded collections Created: 12/Jan/18  Updated: 29/Oct/23  Resolved: 09/May/18

Status: Closed
Project: Documentation
Component/s: None
Affects Version/s: None
Fix Version/s: 3.7.1

Type: Task Priority: Major - P3
Reporter: Kay Kim (Inactive) Assignee: Kay Kim (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
documents SERVER-1981 Support $near and $nearSphere predica... Closed
Related
Participants:
Days since reply: 5 years, 42 weeks, 2 days ago
Epic Link: DOCS: 4.0 Server

 Description   

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.



 Comments   
Comment by Githook User [ 23/Apr/18 ]

Author:

{'email': 'kay.kim@10gen.com', 'username': 'kay-kim', 'name': 'kay'}

Message: DOCS-11389, DOCS-11206: deprecate geoNear cmd, add sharded collection support to $near and $nearSphere
Branch: master
https://github.com/mongodb/docs/commit/13e098768d8682f8c8093c12029cca858188d565

Generated at Thu Feb 08 08:02:18 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.