rednoyz
rednoyz

Reputation: 1327

Custom distance function in mongoose

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

Answers (1)

KARNAV PARGI
KARNAV PARGI

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

Related Questions