[SERVER-3255] $near command should support defining which properties to use for x and y Created: 13/Jun/11  Updated: 06/Dec/22

Status: Open
Project: Core Server
Component/s: Geo
Affects Version/s: None
Fix Version/s: features we're not sure of

Type: Improvement Priority: Major - P3
Reporter: Oliver Gierke Assignee: Backlog - Query Execution
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Execution
Backwards Compatibility: Fully Compatible
Participants:

 Description   

Currently the documentation regarding geospatial index says:

{blockquote}
In order to use the index, you need to have a field in your object that is either a sub-object or array where the first 2 elements are x,y coordinates (or y,x - just be consistent; it might be advisible to use order-preserving dictionaries/hashes in your client code, to ensure consistency).{blockquote}

This feels a bit weird as in no other place of document usage field order actually matters. So in case the location is a nested document it would be cool if we could specify the the properties to be used for comparison on index definition side or when querying:

Index: {'location' : '2d' }, Options: { "name" : "location" , "min" : -180 , "max" : 180, "x" : "foo", "y" : "bar"}

or

{'location' : { '$near' : { 'foo' : 10, 'bar' : 12}}}

I'd prefer the former as this wouldn't require the mapping information to be restated for every query.



 Comments   
Comment by Oliver Gierke [ 23/Aug/11 ]

If so, then at least the Java driver's BasicBSONObject has equals(…) and hashCode(…) implemented invalidly as they compare DBObjects based on their key sets where as Set implies the order to be unspecified.

Comment by Eliot Horowitz (Inactive) [ 14/Jun/11 ]

There are actually a number of things where order matters, including all commands, etc...
Issue noted though - so will consider.

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