javascript - Getting the index of an object in an ordered list in Firebase -


I am creating a leaderboard using Firebase. In the leaderboard the player's position is tracked using the firebase preference system.

At some point in the performance of my program, I need to know what is the position of the user given in the leaderboard. I have thousands of users, so to find something with a single ID, running through them all (thus giving me an indication) is not really an option.

Is there any definite method

edit : I am trying to find out the following:

  / - --- Leaderboard -------- user4 {...} -------- user1 {...} -------- user3 {...} & lt; - Is there a snapshot of User3's index, user 3? --------...    

If you process tens Whether there are hundreds of elements and there is no objection to taking any bandwidth hits, look for the answer to BUT .

If you are processing the resources of the records, then you have to follow the stated approach, the answer to the peperin in theory. Description of the following answer.

Step 1: Setup flashlight to your leaderboard with elastic search

Torchlight is a convenient node script that syncs flexible search with firebase data.

Step 2: Modify the flashlight so that you allow the query option to ElasticSearch

this As a writing, torchlight does not give you a way to do an elastic search, you only document and not document itself

Which uses a simple one-line fix to add this functionality if you do not stop when you read this reply, then just change your copy / manually fork torch .

Step 3: Query!

The query that I sent through fireworks:

  {index: 'firebase', type: 'all time', query: {"filtered": { "Query": {"match_all": {}}, "filter": {"range": {"points": {"gte": minPoints}}}}}, option: {"search_type": "count"} };   

Change the numeral with the name of the field tracking points for your users, and the minimum point with the number of that user's number You are interested in the rank.

The response will look like this:

  {max_core: 0, total: 2}   

total Is the number of users who have the same or more number of points - in other words, the user's rank!

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -