[SERVER-1981] Support $near and $nearSphere predicates on sharded collections Created: 20/Oct/10  Updated: 15/May/18  Resolved: 28/Dec/17

Status: Closed
Project: Core Server
Component/s: Geo, Sharding
Affects Version/s: None
Fix Version/s: 3.7.1

Type: New Feature Priority: Major - P3
Reporter: Mathias Stearn Assignee: Tess Avitabile (Inactive)
Resolution: Done Votes: 22
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
is documented by DOCS-11206 Docs for SERVER-1981: Support $near a... Closed
Duplicate
is duplicated by SERVER-12399 $geoNear operator does not work in sh... Closed
Related
related to SERVER-32310 Log a warning that the geoNear comman... Closed
related to SERVER-926 geo search sharding support Closed
is related to SERVER-5236 $near query should return results pro... Closed
Backwards Compatibility: Fully Compatible
Sprint: Query 2018-01-01
Participants:

 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 [ 28/Dec/17 ]

Author:

{'username': 'tessavitabile', 'email': 'tess.avitabile@mongodb.com', 'name': 'Tess Avitabile'}

Message: SERVER-1981 Support near and nearSphere predicates on sharded collections
Branch: master
https://github.com/mongodb/mongo/commit/f98cb60d80f281d3065b0282ed6f25b5f419ae1b

Comment by Eyllo [ 24/Mar/14 ]

Hi there,

So is this in 2.6.0 rc2 already? Because we aren't able to use Mongo sharded as we heavily rely on this feature. Thanks!

Comment by Mathias Stearn [ 27/Feb/12 ]

geoNear already supports limit (called "num" SERVER-5113) but not skip. I'm not sure if skip really makes sense, but it could probably be added pretty easily. If you want that please make a seporate ticket.

Currently neither geoNear or $near support using cursors and must return all results within a single batch.

Comment by Nick Gerner [ 24/Feb/12 ]

if we had this feature, would we have features like limit, skip and cursor support in geoNear?

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