mardi 24 février 2015

Compare each result to initial document mongoose

I need to run a comparison between a user and other users and then for each match I need to do the same comparison the other way round. Is there anyway of performing this without looping through the users that are returned and manually working it out.


Here is some simplified code... i.e.



User.find(
{
rating: { $gte: currentUserRangeMin,$lte: currentUserRangeMax}
},function(err,users){
for (var i=0;i<users.length;i++){
var rating = users[i].rating;
var range = users[i].preferences.range;
var rangeMax = rating + range;
var rangeMin = rating - range;

if(rangeMax >= currentUserRating && rangeMin <= currentUserRating){
//include in results.
}else{
//exclude from results.
}
}
});


I'm also using an offset for pagination and don't want to always have to return every user that matches every time.


Is there a better way of doing this?


Aucun commentaire:

Enregistrer un commentaire