[SERVER-3297] Bounding box queries in embedded geo documents (Mongo v1.9) not working properly Created: 20/Jun/11 Updated: 30/Mar/12 Resolved: 21/Jun/11 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Geo |
| Affects Version/s: | 1.9.0 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | ramesh vel | Assignee: | Greg Studer |
| Resolution: | Done | Votes: | 0 |
| Labels: | geo, indexing, query | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Platform independent |
||
| Operating System: | Linux |
| Participants: |
| Description |
|
Bounding box queries inside the embedded documents are giving inaccurate results. Sample document "_id" : ObjectId("4dff052e1d41c8588000000a"), , , , when issuing the $box query with this co-ordinates [[80.21758681346137, 13.04706625300893], [80.2238953690644, 13.052333939665253]], it should not pick the above item db.items.find({"locations.is_exact":true,"locations.loc" : {"$within" : {"$box" :[[80.21758681346137, 13.04706625300893], [80.2238953690644, 13.052333939665253]] }}}) But this query picks the above item. So i created another document(not embedded) with the same data & location. like this "_id" : ObjectId("4dff052e1d41c8588000000a"), and used the same box query db.items.find({loc : {"$within" : {"$box" :[[80.21758681346137, 13.04706625300893], [80.2238953690644, 13.052333939665253]] }}}) now it works fine. it doesn't pick up the item. So this problem only exists in v1.9 geo indexes in embedded documents |
| Comments |
| Comment by ramesh vel [ 24/Jun/11 ] |
|
Greg, |
| Comment by Greg Studer [ 24/Jun/11 ] |
|
I don't mean to offend you or minimize your issue, we just tend to be concise. If you have a coll with a non-geo document like: , { is_exact : false, loc : 1 }] } and you search for: ) , { is_exact : false, loc : 1 }] } In order to do individual subdocument matching, you need to use the $elemMatch operator: } }) This operator isn't yet supported by geospatial queries - I've created an improvement ticket that you can vote on if you think it should be: |
| Comment by ramesh vel [ 22/Jun/11 ] |
|
Greg Studer, db.items.find({"locations.is_exact":true,"locations.loc" : {"$within" : {"$box" :[[80.21758681346137, 13.04706625300893], [80.2238953690644, 13.052333939665253]] }}}) So the query must look only into the first embedded document "name" : "Samiyar Madam, Kodambakkam, Chennai, Tamil Nadu, India", not the one you have mentioned [ 80.223766, 13.049043 ] one. { Also, if it works perfectly, it should work in both normal & embedded documents. But its not. So its an issue. So please re-open the issue, its a important one. |
| Comment by Greg Studer [ 21/Jun/11 ] |
|
Think this is working properly? The third point: [ 80.223766, 13.049043 ] is inside the box: [[80.21758681346137, 13.04706625300893], [80.2238953690644, 13.052333939665253]] I'm guessing you're trying to search for documents with all points within a region? - $within queries find documents with any points inside a region, right now there's no automatic way to get those results, you'd have to filter them on the client side. If this is what you were expecting and it's important for your use case, I'd recommend creating (a different) improvement JIRA case. |