[SERVER-63757] maxDistance field on GeoNear query not accepting field number Created: 17/Feb/22  Updated: 17/Feb/22  Resolved: 17/Feb/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: Unassigned
Resolution: Duplicate Votes: 0
Labels: geoNear
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-63756 maxDistance field on GeoNear query no... Closed
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]}

,
"distanceField": "dist.calculated",
"maxDistance": "max_travel_radius",
"key": "address_geopoint",
"uniqueDocs": "True"
}

 

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]}

,
"distanceField": "dist.calculated",
"maxDistance": "max_travel_radius",
"key": "address_geopoint",
"uniqueDocs": "True"
}



 Comments   
Comment by Edwin Zhou [ 17/Feb/22 ]

Hi rebekahmark12@gmail.com,

I noticed that this ticket duplicates another ticket you recently opened, so I will close it as a duplicate against SERVER-63756.

Best,
Edwin

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