[SERVER-12987] $geoWithin does not return results Created: 02/Mar/14  Updated: 10/Dec/14  Resolved: 03/Mar/14

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

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

Attachments: File server12987.js    
Operating System: ALL
Steps To Reproduce:

 
db.createCollection( "testGeoWithin" );
 
db.testGeoWithin.insert(
{
        "geometry" : {
                "location" : {
                        "lng" : -73.771799,
                        "lat" : 41.033431
                }
        },
        "types" : [
                "school",
                "establishment"
        ]
} );
 
 
db.testGeoWithin.ensureIndex( {"geometry.location" : "2d" } );
 
db.testGeoWithin.find( {"types":{"$in":["school"]},"geometry":{"$geoWithin":{"$geometry":{"type":"Polygon","coordinates":[[[-73.765358810837,41.036711084713],[-73.773316461021,41.036711084713],[-73.773316461021,41.031802162346],[-73.765358810837,41.031802162346],[-73.765358810837,41.036711084713]]]}}}} );
 

Participants:

 Description   

db.testGeoWithin.insert(
{
        "geometry" : {
                "location" : {
                        "lng" : -73.771799,
                        "lat" : 41.033431
                }
        },
        "types" : [
                "school",
                "establishment"
        ]
} );
 
db.testGeoWithin.ensureIndex( {"geometry.location" : "2d" } );
 
db.testGeoWithin.find( {"types":{"$in":["school"]},"geometry":{"$geoWithin":{"$geometry":{"type":"Polygon","coordinates":[[[-73.765358810837,41.036711084713],[-73.773316461021,41.036711084713],[-73.773316461021,41.031802162346],[-73.765358810837,41.031802162346],[-73.765358810837,41.036711084713]]]}}}} );

Should return the inserted doc.
Btw, it works just fine in 2.4.6.



 Comments   
Comment by Benety Goh [ 03/Mar/14 ]

You're welcome!

Comment by Pavel Baranov [ 03/Mar/14 ]

Got it, it works with "geometry.location" Thank you!

Comment by Benety Goh [ 03/Mar/14 ]

Can you change your query to run against "geometry.location"?

Instead of

...,"geometry":{"$geoWithin": ...

Try:

...,"geometry.location":{"$geoWithin": ...

Comment by Pavel Baranov [ 03/Mar/14 ]

I'm confused. I don't need coordinates returned, I need _id returned and this query is not matching it but it should.
"geometry" : {
"location" :

{ "lng" : -73.771799, "lat" : 41.033431 }

}
IS within this polygon: [[[-73.765358810837,41.036711084713],[-73.773316461021,41.036711084713],[-73.773316461021,41.031802162346],[-73.765358810837,41.031802162346],[-73.765358810837,41.036711084713]]]

Comment by Benety Goh [ 03/Mar/14 ]

This is unsupported behavior. Running a $geoWithin query against 'geometry' should not return coordinates in nested field 'geometry.location'.

It's a bug in 2.4:

https://github.com/mongodb/mongo/blob/v2.4/src/mongo/db/matcher.cpp#L963

The code was intended to iterate over an array but also iterated into subdocuments.

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