[SERVER-63756] maxDistance field on GeoNear query not accepting field number Created: 17/Feb/22 Updated: 27/Oct/23 Resolved: 04/Mar/22 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | 4.2 Required |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Rebekah Mark | Assignee: | Edwin Zhou |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | geoNear | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Operating System: | ALL | ||||||||
| Steps To Reproduce: | 1. Create any mongo document that includes a float or number field for the max travel radius, and an address field as points coordinates. Then try to pull the max travel radius field in for maxDistance, and the address field in for key (this part works fine when maxDistance is a hard coded number). Below is a basic example of the document structure. { "_id":"apitestuser", "address_geopoint": { "type":"Point","coordinates": [-111.8905343,40.7661073]}, "max_travel_radius":10.1 }
2. Select the aggregation pipeline in Mongo Compass (I have tried running this same query in a python IDE and get the same result, so it's not a Mongo Compass specific bug) and choose GeoNear. Paste the following code in: { "near": \{type: "Point", coordinates: [-111.887277, 40.770020]},
3. After the code is pasted it should automatically produce the error 'maxDistance must be a number'.
4. Change the maxDistance field from "max_travel_radius" to 3000 for testing purposes. It should run fine.
I need this to pull in the document field and not require only the hard coded value, which from reading the documentation has led me to believe is possible and this is a bug. |
||||||||
| Participants: | |||||||||
| Description |
|
I have the following GeoNear aggregation I am running some documents. max_travel_radius is a float field on the objects that I am trying to pull into the maxDistance field for the aggregation, and is different for each document. Each time I run the query, it produces the error 'maxDistance must be a number', never allowing me to use a field although running it with a single, hard coded number works.
Ultimately what I am trying to do is send out a request for service from one customer application (the 'near' field) and check if there are any service providers (the 'key' field, which I have as point coordinates on the document) and only return providers which are within the given search radius ('maxDistance'). Each service provider document should be able to set their own max travel distance as a stored variable which can then be used in the GeoNear query to check if they are within range of a new service request.
Here is an example of a GeoNear query I am running: { "near": \{type: "Point", coordinates: [-111.887277, 40.770020]}, |
| Comments |
| Comment by Edwin Zhou [ 04/Mar/22 ] |
|
Thanks for your patience. I've investigated this issue further and I believe this behavior Works as Designed. The $geoNear aggregation stage queries for documents near a given point, and the max distance filters out documents exceeding the specified distance. The maxDistance field is not intended to be defined with input documents and it wouldn't work with the use case you described. If you need further help troubleshooting, I recommend reaching out to our MongoDB Developer Community Forums. Best, |
| Comment by Rebekah Mark [ 28/Feb/22 ] |
|
Thank you so much! Eagerly awaiting what you find. |
| Comment by Edwin Zhou [ 28/Feb/22 ] |
|
Thank you for following up that you have already attempted to reference the field path with a $ prefix. I've been able to reproduce this issue and will continue investigating. Best, |
| Comment by Rebekah Mark [ 28/Feb/22 ] |
|
If you follow the steps I listed to reproduce it will likely give you a |
| Comment by Rebekah Mark [ 28/Feb/22 ] |
|
I would appreciate it if you could keep this issue open and not marked as |
| Comment by Rebekah Mark [ 28/Feb/22 ] |
|
Hi Edwin - Rebekah |
| Comment by Edwin Zhou [ 28/Feb/22 ] |
|
Thank you for your report. Based on an initial look, it appears that in your aggregation pipeline, you're attempting to reference a field path. When doing so, you must prefix the field path name with a dollar sign $. For this issue we'd like to encourage you to start by asking our community for help by posting on the MongoDB Developer Community Forums. If the discussion there leads you to suspect a bug in the MongoDB server, then we'd want to investigate it as a possible bug here in the SERVER project. Best, |