Sign In Register

How can we help you today?

Start a new topic
Answered

Running leaderboard queries with a 'not in' clause

Hi all,


I need to be able to run a leaderboard query that filters out a set of users that the player has already connected with. I can run a standard mongo query against a leaderboard collection through the portal as such :


{Level:{$gt:10}}, {userId:{$nin:[<userid>. ..., <userid>]}}


But... I cannot find a way to do this in cloud code. It appears that Leaderboard collections are hidden behind Spark.getLeaderboards().getLeaderboard(<name>) without access to the underlying collection.


Any help here greatly appreciated!


Thanks,

- Toby


Best Answer

ok, thanks for that.


We currently have an AroundMeLeaderboardDataRequest, but this is either everyone or just friends.


What I'd really like to do is add another options parameter to this call "excludeIds" which will do exactly what you need. 


I'd need to schedule this, and we would be able to get it out in early April, is this acceptable?


If not, let me know as there are some other less clean approaches we could use.


Gabriel


Hi Toby


This is a good question, it's not something thats been asked before. 


Could you explain your use case a little further? What do you plan to do with these players once returned?


Gabriel

The use case is for matchmaking people to bring an ally with them into battle. After the battle, the ally can be added as a friend - a friend list that we manage in a collection containing a list per player. I'm using a single leaderboard that tracks all players by level to make the query.


So what I want to do is ideally select a window around the players level that includes up to <n> entries but excludes the players friends. The obvious solution i came up with was to simply select <n> + current friend count and let the client deal with existing friends. The downside is the query returning a larger than optimal set.


I'm guessing that redis or something similar is being used for the leaderboard system?


I hope my answer provides enough detail.


- Toby

Answer

ok, thanks for that.


We currently have an AroundMeLeaderboardDataRequest, but this is either everyone or just friends.


What I'd really like to do is add another options parameter to this call "excludeIds" which will do exactly what you need. 


I'd need to schedule this, and we would be able to get it out in early April, is this acceptable?


If not, let me know as there are some other less clean approaches we could use.


Gabriel

Yep - the current solution is to use the AroundMeLeaderboardDataRequest and just request an extra set that covers the potential of including friends. We can run with that for now and then use an exclusion method when it comes online. April is fine!


Thanks Gabriel,


- Toby 

Login to post a comment