Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

349
Vistas
$geoNear error when trying to find the near users

When I am trying to run this code with other aggregation objects, it fails when getting near users. error it give me is MongoServerError: geo near accepts just one argument when querying for a GeoJSON point. Extra field found: $maxDistance: 16093.4

Here is my code when it makes an error:

let aggregatePipeline = [];
aggregatePipeline.push({
    $geoNear: {
      near: {
        type: "Point",
        coordinates: [longitude, latitude],
      },
      distanceField: "distance",
      spherical: true,
      maxDistance: radius,
      //minDistance: <number in meters>, you can also add minimum distance to this aggregation
    },
  });

here is where I run my pipeline:

const sellers= await Seller.aggregate(aggregatePipeline).exec();

and here is the model for my seller schema:

const sellerSchema = new mongoose.Schema({
  user_id: {
    type: mongoose.Schema.Types.ObjectId,
    ref: "User",
  },
  ...,
  location: {
    type: { type: String, default: "Point" },
    coordinates: [], // ! <longitude, latitude> ex. coordinates [47, 23.224434]
  },
  timestamp: {
    type: Date,
    default: Date.now,
  },
});

I might be running the $geoNear incorrectly or maybe I can use another argument.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda