{"record":{"id":"c0c2237cbe900c7d","repo":"meteor/meteor","slug":"near-argument-must-be-coordinate-pair-or-geojson","errorCode":null,"errorMessage":"$near argument must be coordinate pair or GeoJSON","messagePattern":"\\$near argument must be coordinate pair or GeoJSON","errorType":"exception","errorClass":"MiniMongoQueryError","httpStatus":null,"severity":"error","filePath":"packages/minimongo/common.js","lineNumber":440,"sourceCode":"          return GeoJSON.pointDistance(\n            point,\n            {type: 'Point', coordinates: pointToArray(value)}\n          );\n        }\n\n        if (value.type === 'Point') {\n          return GeoJSON.pointDistance(point, value);\n        }\n\n        return GeoJSON.geometryWithinRadius(value, point, maxDistance)\n          ? 0\n          : maxDistance + 1;\n      };\n    } else {\n      maxDistance = valueSelector.$maxDistance;\n\n      if (!isIndexable(operand)) {\n        throw new MiniMongoQueryError('$near argument must be coordinate pair or GeoJSON');\n      }\n\n      point = pointToArray(operand);\n\n      distance = value => {\n        if (!isIndexable(value)) {\n          return null;\n        }\n\n        return distanceCoordinatePairs(point, value);\n      };\n    }\n\n    return branchedValues => {\n      // There might be multiple points in the document that match the given\n      // field. Only one of them needs to be within $maxDistance, but we need to\n      // evaluate all of them and use the nearest one for the implicit sort\n      // specifier. (That's why we can't just use ELEMENT_OPERATORS here.)","sourceCodeStart":422,"sourceCodeEnd":458,"githubUrl":"https://github.com/meteor/meteor/blob/5076d2f818d3cac01d0cf8312fa5b2332076a4fb/packages/minimongo/common.js#L422-L458","documentation":"Thrown by the $near operator in legacy coordinate-pair mode when the operand is not indexable as a coordinate pair. $near supports two forms: GeoJSON (operand has $geometry) and legacy [x, y] arrays. The else branch calls isIndexable(operand); if it is not a valid coordinate pair, the error is raised before pointToArray.","triggerScenarios":"Using {field: {$near: 'point'}}, {field: {$near: 5}}, {field: {$near: {lat:1,lng:2}}} (object without $geometry), or {field: {$near: [1]}} (single-element array) in a minimongo query.","commonSituations":"Passing a GeoJSON-like object but omitting the $geometry wrapper; passing lat/lng as a plain object instead of [lng, lat]; passing fewer/more than two coordinates; confusing latitude-first vs longitude-first ordering.","solutions":["For legacy pairs, pass a two-number array in [longitude, latitude] order: {field: {$near: [lng, lat], $maxDistance: 1000}}.","For GeoJSON, wrap the geometry in $geometry: {field: {$near: {$geometry: {type: 'Point', coordinates: [lng, lat]}, $maxDistance: 1000}}}.","Validate the operand is a 2-element numeric array or contains $geometry before building the selector."],"exampleFix":"// before\ncollection.find({ loc: { $near: { lat: 40, lng: -73 } } });\n// after\ncollection.find({ loc: { $near: [-73, 40], $maxDistance: 1000 } });","handlingStrategy":"validation","validationCode":"function nearSelector(operand, maxDistance) {\n  const isPair = Array.isArray(operand) && operand.length === 2 && operand.every(Number.isFinite);\n  const isGeoJSON = operand && typeof operand === 'object' && '$geometry' in operand;\n  if (!isPair && !isGeoJSON) {\n    throw new TypeError('$near needs [lng,lat] or {$geometry: GeoJSON}');\n  }\n  const sel = { $near: operand };\n  if (maxDistance !== undefined) sel.$maxDistance = maxDistance;\n  return sel;\n}","typeGuard":"function isCoordinatePair(op) {\n  return Array.isArray(op) && op.length === 2 && op.every(v => typeof v === 'number' && Number.isFinite(v));\n}\nfunction isGeoJSONNear(op) {\n  return op !== null && typeof op === 'object' && '$geometry' in op;\n}","tryCatchPattern":null,"preventionTips":["Pass [longitude, latitude] two-number arrays for legacy $near.","Wrap GeoJSON in $geometry for 2dsphere queries.","Validate operand shape at the selector-builder boundary."],"tags":["minimongo","query","operator","geo","near","validation"],"backgroundTag":null,"analyzedSha":"5076d2f818d3cac01d0cf8312fa5b2332076a4fb","analyzedAt":"2026-08-13T03:27:40.142Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}