I have a dating app, and I store all the potential Match objects in MongoDB (a Match object happens when user swipes left or right):
{
uid1: <userid1>,
uid2: <userid2>,
uid1action: <L|R|E> (left/right/empty, based what the user1 has done),
uid2action: <L|R|E> (left/right/empty, based what the user2 has done),
}
Now comes to my question. When I show profiles of potential users to user1, I take in to account all the people who already have liked user1 (because I prioritise these profiles):
var likedQuery = Parse.Query.or(new Parse.Query("Match")
.equalTo("uid1", userId)
.equalTo("u2action", "L")
.equalTo("u1action", "E") // user1 has not done anything
.select("uid2")
.limit(paginationLimit);
Now this is nice, everything works nicely. I am now looking to also order the likedQuery by the amount of likes each user has (popularity).
Say these are the following users who have liked user1:
Paul (paul himself has had 50 people like him)
Logan (logan was liked by 20 people)
Michael (michael was liked by 80 people),
We want to order all these people such that Michael would be the first profile user1 sees.
Now my question is, how will I do it using mongoDB? In SQL this would be quite trivial, just do a table JOIN, order by that table using SUM() and COUNT(), and ensure you have necessary indexes.
In mongoDB, the only way I see how to do it is to have a uid2likes (which will be sorted on) field on each Match object that will be incremented by cron job, but that is ridiculous and doesn't scale.
My question is more about how to do this in a way that scales.