[SERVER-5571] Issue when using spatial query within filter using $and Created: 11/Apr/12 Updated: 15/Aug/12 Resolved: 20/Apr/12 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | 2.1.0 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | M Schaffer | Assignee: | siddharth.singh@10gen.com |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows 7 32 bit |
||
| Operating System: | ALL |
| Participants: |
| Description |
|
I am getting errors when I try a spatial query within an "$and" operator. I can run the following queries successfully: db.LOGGER.find({ "COORDINATES" : { "$within" : { "$polygon" : [[22000, 60000], [22000, 63000], [23000, 63000], [23000, 60000]] } } }); }, { "TIME" : { "$lt" : NumberLong("3542546575557") }}] }); However when I add the spatial query to the "$and" I get the following error: db.LOGGER.find({ "$and" : [{ "COORDINATES" : { "$within" : { "$polygon" : [[22000, 60000], [22000, 63000], [23000, 63000], [23000, 60000]] }} },{ "TIME" : { "$gte" : NumberLong("3542546522557") }}, { "TIME" : { "$lt" : NumberLong("3542546575557") }}] }); error: { } }, { TIME: { $gte: 3542546522557 }}, { TIME: { $lt: 3542546575557 } } ] }", I have a collection with the following format: } db.LOGGER.getIndexes() , , |
| Comments |
| Comment by siddharth.singh@10gen.com [ 14/Apr/12 ] |
|
Yes, a compound index on secondary keys (in your case time field) should help you with what you are trying to do. Please see this similar discussion on google groups http://groups.google.com/group/mongodb-user/browse_thread/thread/4417b0f9f0b3de12 |
| Comment by M Schaffer [ 14/Apr/12 ] |
|
What is wrong with the spatial index that I have already added (see above)? |
| Comment by siddharth.singh@10gen.com [ 12/Apr/12 ] |
|
Hi, $and is not needed to do what you want to do. You need to have a Geospartial index on you collection like it is explained here: http://www.mongodb.org/display/DOCS/Geospatial+Indexing#GeospatialIndexing-CompoundIndexes |