I am developing a small NodeJS web application using Mongoose to access my MongoDB database. The following is a simplified diagram of my collection:
var MySchema = mongoose.Schema({
content: { type: String },
location: {
lat: { type: Number },
lng: { type: Number },
},
modifierValue: { type: Number }
});
Unfortunately, I cannot sort the received data from the server in a way that is more convenient for me. I want to sort the results according to their distance from a given position (location), but taking into account the modifier function with the Value modifier, which is also considered as an input.
What I intend to do is written below. However, this sorting function does not seem to exist.
MySchema.find({})
.sort( modifierFunction(location,this.location,this.modifierValue) )
.limit(20)
.exec(callback)
The mondifier function returns Double.
So far I have been exploring the possibility of using the mongoose $ near function, but this does not seem to sort, the modifier does not allow.
node.js mongoose, , .
,