[SERVER-13218] unable to $and multiple geospatial queries Created: 15/Mar/14  Updated: 10/Dec/14  Resolved: 15/Mar/14

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

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

Operating System: ALL
Participants:

 Description   

It looks like it has been fixed in 2.5.5 (https://jira.mongodb.org/browse/SERVER-4572)
However, I'm using 2.6.0-rc2-pre- and the following query fails:

 
db.main.find( { $and : [ { "coords": {"$geoWithin": {"$geometry": {"type":"Polygon", "coordinates": [[[-73.650458551013,41.01805351145],
                                                                                                      [-73.699751260364,41.01805351145],
                                                                                                      [-73.699751260364,40.988362588689],
                                                                                                      [-73.650458551013,40.988362588689],                                                                                                                                                                                       
                                                                                                      [-73.650458551013,41.01805351145]]]}}}},                         
                        {"coords":{"$near":{"$geometry":{"type":"Point","coordinates":[-73.6647,41.000732]}}, "$maxDistance":1609.3470878864}}] },               
              {_id:1}
);
 
error: {
        "$err" : "Can't canonicalize query: BadValue geo near accepts just one argument when querying for a GeoJSON point. Extra field found: $maxDistance: 1609.3470878864",
        "code" : 17287
}



 Comments   
Comment by Pavel Baranov [ 16/Mar/14 ]

Perfect. Thank you!

Comment by Daniel Pasette (Inactive) [ 15/Mar/14 ]

This is because of stricter parsing rules around $maxDistance. The $maxDistance needs to be in the $geometry sub-document in your query.

The change is documented here:
http://docs.mongodb.org/master/release-notes/2.6-compatibility/#maxdistance-changes

Try:

db.main.find( { $and : [ { "coords": {"$geoWithin": {"$geometry": {"type":"Polygon", "coordinates": [[[-73.650458551013,41.01805351145], [-73.699751260364,41.01805351145], [-73.699751260364,40.988362588689], [-73.650458551013,40.988362588689], [-73.650458551013,41.01805351145]]]}}}}, {"coords":{"$near":{"$geometry":{"type":"Point","coordinates":[-73.6647,41.000732]},$maxDistance:1 } }}] }, {_id:1});

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