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.