Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-63757

maxDistance field on GeoNear query not accepting field number

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 4.2 Required
    • Component/s: None
    • ALL
    • Hide

      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.

      Show
      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.

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

            Assignee:
            Unassigned Unassigned
            Reporter:
            rebekahmark12@gmail.com Rebekah Mark
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: