Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

337
Views
$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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!