Reputation: 1327
I have a custom distance function (cDistance) that compares items of type User. And I need to find the set of closest Users to the current user, according to this metric. Something like:
Given User A, return the 10 closest Users according to the cDistance(A,B) function.
How can I do this with Mongoose/MongoDB ?
Upvotes: 1
Views: 81
Reputation: 653
you can use $lte and $gte for your query.
async function cDistance(A,B){
let query = {$match:{distance:{$gte:Number(a), $lte:Number(b)}}}
let data =await MainQuery.aggregate(query)
or
let data = await Query.find({distance:{$gte:Number(a), $lte:Number(b)}})
return data;
}
Upvotes: 1