I am having some difficulty with my leaderboard for my application. I have a database with two collections.
- Users
- Fish
In my Fish collection I also have user_id. When I fetch all fish, I get everything including user_id. However, the user_id doesn't really help me, I want to display the username belonging to that user_id.
This is how my query looks.
Fish.find().sort({weight: -1}).limit(10).exec(function(err, leaderboard) {
if(err) return res.json(500, {errorMsg: 'Could not get leaderboard'});
res.json(leaderboard);
})
I feel like I need to make another query, to get all the usernames belonging to the user_ids I get from the first query. Perhaps use a loop somehow?
MongoDb is pretty new to me and don't really know what to look for. Any advice, tips, link are much appriecated.