0

I'm in PHP and i have a document that may have a location or not and I use geonear on it. I want to keep the location with null value. How can i do ?

[
   '$geoNear' => [
       'near' => [
          'type' => 'Point',
          'coordinates' => [$logitude, $latitude],
       ],
       'query' => [
          'matchingUUID' => $uuid,
       ],
       'distanceField' => 'destination.calculatedDistance',
       'spherical' => true,
   ],
]

Thanks a lot

MMS
  • 23
  • 2
  • You really cannot. You *"can"* with standard "query" operators like `$near` or `$nearSphere` to *some* degree by including in an `$or`. But the projection of distance offered by `$geoNear` does not allow for such an "OR" condition. Nor would it make **ANY** sense to do so since afterall, "What is the distance from `null`?" If you have an answer to that, then please tell me since I do not not what the distance from `null` is. – Neil Lunn Nov 02 '19 at 10:21
  • If for some reason you see fit to include data with no disclosed location ( and therefore no calculable distance ) within the set of results that should be "near" a specified location, then I suggest you do this with separate queries and select those `null` locations in the other query operation. This is not something you really should expect MongoDB to do as a "feature". – Neil Lunn Nov 02 '19 at 10:25

0 Answers0