[DOCS-12834] Document that $geoWithin cannot contain multiple fields Created: 14/Jun/19  Updated: 30/Oct/23

Status: Closed
Project: Documentation
Component/s: Server
Affects Version/s: 4.0.9
Fix Version/s: Server_Docs_20231030

Type: Improvement Priority: Major - P3
Reporter: Mateusz Starzec Assignee: Unassigned
Resolution: Won't Do Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 1 year, 14 weeks, 2 days ago

 Description   

$geoWithin cannot contain an implicit $and and must only have one field. We should clearly indicate this in the documentation. There may be other operators that also need to be clarified.

Original Description

Parser rejects the following query:

{"coordinates": {
    "$geoWithin": {"$centerSphere": [[22, 52], 0.04]},
    "$not": {
        "$geoWithin": {"$centerSphere": [[22, 52], 0.01]}
    }
}}

with the following error:

{
	"ok" : 0,
	"errmsg" : "can't parse extra field: $not: { $geoWithin: { $centerSphere: [ [ 22.0, 52.0 ], 0.001 ] } }",
	"code" : 2,
	"codeName" : "BadValue"
}

Tested on Mongo 4.0.9



 Comments   
Comment by Education Bot [ 31/Oct/22 ]

Hello! This ticket has been closed due to inactivity. If you believe this ticket is still important, please reopen it and leave a comment to explain why. Thank you!

Comment by Danny Hatcher (Inactive) [ 26/Jun/19 ]

After some internal discussions, we believe that the simple workaround of writing the query with an $and should be sufficient for most use-cases. For example, you could rewrite your query like so:

{$and:
  [
    { coordinates: { $geoWithin: { $centerSphere: [ [ 22, 52 ], 0.04 ] } } },
    { coordinates: { $not: { $geoWithin: { $centerSphere: [ [ 22, 52 ], 0.01 ] } } } }
  ]
}

However, we should be more clear about the fact that $geoWithin cannot contain an implicit $and and must only have one field. I will convert this ticket to a Docs ticket to address this.

Comment by Danny Hatcher (Inactive) [ 21/Jun/19 ]

Thanks for your report. We're looking into whether this behavior is working as intended or is something that should be fixed. I will update this ticket as soon as we decide.

Generated at Thu Feb 08 08:06:13 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.