[SERVER-54764] Geo predicates should not inspect neighboring elements Created: 24/Feb/21  Updated: 27/Dec/23

Status: Backlog
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Charlie Swanson Assignee: Backlog - Query Integration
Resolution: Unresolved Votes: 0
Labels: qi-geo
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File narrow_geo_parse.patch    
Issue Links:
Related
Assigned Teams:
Query Integration
Participants:

 Description   

It looks like at least $geoWithin and $geoIntersects will reject sibling predicates on the same field. This is inconsistent with other path-accepting predicates like $lt and $gt:

> db.foo.find({x: {$geoWithin: {"$centerSphere": [[22.0, 52.0], 0.04]}, $lt: 2}})
Error: error: {
        "ok" : 0,
        "errmsg" : "can't parse extra field: $lt: 2.0",
        "code" : 2,
        "codeName" : "BadValue"
}
> db.foo.find({x: {$gt: 0, $lt: 2}})

For $near it looks like there is some 'legacy' form of the query which we are able to parse which needs to look at neighboring elements:

> db.foo.createIndex({loc: "2d"})
{
        "numIndexesBefore" : 1,
        "numIndexesAfter" : 2,
        "createdCollectionAutomatically" : false,
        "ok" : 1
}
> db.foo.find({loc: {$near: [0, 0], $minDistance: 1}})
> db.foo.find({loc: {$near: [0, 0], $minDistance: 1, $gt: 2}})
Error: error: {
        "ok" : 0,
        "errmsg" : "invalid argument in geo near query: $gt",
        "code" : 34413,
        "codeName" : "Location34413"
}

It's unclear whether we should continue to error on unrecognized fields in that context. It's a strange grammar there.



 Comments   
Comment by Charlie Swanson [ 24/Feb/21 ]

I've added narrow_geo_parse.patch which seems to implement this. It's not well tested though. I was just trying to confirm my understanding.

Generated at Thu Feb 08 05:34:25 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.