[SERVER-13546] $near won't accept GeoJSON structure against legacy coordinates. Created: 10/Apr/14  Updated: 23/Jul/15  Resolved: 23/Jul/15

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

Type: Bug Priority: Major - P3
Reporter: Craig Wilson Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Steps To Reproduce:

use test
db.testgeo.createIndex({"geo": "2d"})
db.testgeo.insert({geo: [-96.772827, 32.872667]});

Legacy form works:

db.testgeo.find({geo: { $near: [-96.772827, 32.872667]}})

GeoJson form doesn't work.

db.testgeo.find({ "geo" : { "$near" : { "$geometry" : { "type" : "Point", "coordinates" : [-96.772827, 32.872667] } } } })

Participants:

 Description   

This works correctly from 2.4 -> 2.5.3. It begins failing in 2.5.4 and is still broken in 2.6. Server ticket SERVER-9341 seems to indicate this is not supported, but our documentation indicates that geoJson is an accepted format for 2D indices. In addition, since this works correctly in 2.4.10, it seems that this should continue to work; otherwise it is a backwards breaking change.

Error Message:

QueryFailure flag was Unable to execute query: error processing query: ns=milieu.venues limit=4 skip=0
Tree: GEONEAR  field=location.geo maxdist=1.79769e+308 isNearSphere=0 First: notFirst: full path: location.geo
Sort: {}
Proj: {}
 planner returned error: unable to find index for $geoNear query (response was { "$err" : "Unable to execute query: error processing query: ns=milieu.venues limit=4 skip=0\nTree: GEONEAR  field=location.geo maxdist=1.79769e+308 isNearSphere=0 First: notFirst: full path: location.geo\nSort: {}\nProj: {}\n planner returned error: unable to find index for $geoNear query", "code" : 17007 }).



 Comments   
Comment by Siyuan Zhou [ 23/Jul/15 ]

Current documentation reflects the correct behavior of $near, so I'm closing this one as "Work as Designed."

Comment by Mikhail Ivanov [X] [ 22/Sep/14 ]

I looked through both documentation and sources. Documentation indicates that usage of GeoJSON in $near requires 2dsphere index. 2d indices supperted only for legacy version.
In code it comes through GeoNearExpression::parseFrom when it calls parseNewQuery method and than it comes through GeoParser::parseQueryPoint to parseGeoJSONPoint which always project coordinates on SPHERE .
So imho it's not a bug but documented behavior

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