'How to find the nearest K documents by euclidean distance on more than two parameters in mongodb?

I have a users collections in mongodb similar to the following.

{
    _id:ObjectID,
    score1:Number,
    score2:Number,
    score3:Number
}

For a given user, how can I find the top K users with the minimum euclidean distance on the three scores? I am using MongoDB and NodeJS.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source