How to get the position of an item in the realtime databaseLeaderboard ranking with FirebaseGetting rank of user from firebase database in androidUnity - Firebase realtime database - Get my rank in leaderboardHow do JavaScript closures work?How do I check if an element is hidden in jQuery?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I redirect to another webpage?How to insert an item into an array at a specific index (JavaScript)?How do I include a JavaScript file in another JavaScript file?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?How do I return the response from an asynchronous call?
Papers on ArXiv as main references
Can a multiclassed Kensei monk/Swashbuckler rogue use an offhand finesse weapon to trigger Sneak Attack, without using a bonus action?
Why does the painters tape have to be blue?
Why is std::ssize() introduced in C++20?
Why'd a rational buyer offer to buy with no conditions precedent?
Split into three!
Are there guidelines for finding good names for LaTeX 2e packages and control sequences defined in these packages?
Time complexity of an algorithm: Is it important to state the base of the logarithm?
How does Dreadhorde Arcanist interact with split cards?
Why A=2 and B=1 in the call signs for Spirit and Opportunity?
How does the Earth's center produce heat?
How would a developer who mostly fixed bugs for years at a company call out their contributions in their CV?
Physical only checkdb is failing, but full one is completed successfully
Can flying creatures choose to hover, even if they don't have hover in their flying speed?
Why is 'additive' EQ more difficult to use than 'subtractive'?
Does water in vacuum form a solid shell or freeze solid?
How do you earn the reader's trust?
How to deceive the MC
Status of proof by contradiction and excluded middle throughout the history of mathematics?
How can I minimize the damage of an unstable nuclear reactor to the surrounding area?
Is "vegetable base" a common term in English?
Complications of displaced core material?
Unary Enumeration
How to escape dependency hell?
How to get the position of an item in the realtime database
Leaderboard ranking with FirebaseGetting rank of user from firebase database in androidUnity - Firebase realtime database - Get my rank in leaderboardHow do JavaScript closures work?How do I check if an element is hidden in jQuery?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I redirect to another webpage?How to insert an item into an array at a specific index (JavaScript)?How do I include a JavaScript file in another JavaScript file?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?How do I return the response from an asynchronous call?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I want to get the position of an item in the database, along with the data.
.ref("users")
.orderByChild("email")
.equalTo(myEmail)
.once("value", snapshot =>
console.log("Database Position", ???? )
Is there a value in the snapshot that I could use that indicates the position in the database (after ordering by email)? I don't want to do this on the client side since I have >1k users
javascript firebase-realtime-database
add a comment |
I want to get the position of an item in the database, along with the data.
.ref("users")
.orderByChild("email")
.equalTo(myEmail)
.once("value", snapshot =>
console.log("Database Position", ???? )
Is there a value in the snapshot that I could use that indicates the position in the database (after ordering by email)? I don't want to do this on the client side since I have >1k users
javascript firebase-realtime-database
Answer below. Since this may indeed not work for you, you might want to explain what you're trying to accomplish here. As it stands your question reads like a XY problem, and if we know the actual goal we may be able to come up with an alternative approach.
– Frank van Puffelen
Mar 23 at 23:24
add a comment |
I want to get the position of an item in the database, along with the data.
.ref("users")
.orderByChild("email")
.equalTo(myEmail)
.once("value", snapshot =>
console.log("Database Position", ???? )
Is there a value in the snapshot that I could use that indicates the position in the database (after ordering by email)? I don't want to do this on the client side since I have >1k users
javascript firebase-realtime-database
I want to get the position of an item in the database, along with the data.
.ref("users")
.orderByChild("email")
.equalTo(myEmail)
.once("value", snapshot =>
console.log("Database Position", ???? )
Is there a value in the snapshot that I could use that indicates the position in the database (after ordering by email)? I don't want to do this on the client side since I have >1k users
javascript firebase-realtime-database
javascript firebase-realtime-database
edited Mar 23 at 23:19
Frank van Puffelen
253k31407435
253k31407435
asked Mar 23 at 21:42
gvon79gvon79
64212
64212
Answer below. Since this may indeed not work for you, you might want to explain what you're trying to accomplish here. As it stands your question reads like a XY problem, and if we know the actual goal we may be able to come up with an alternative approach.
– Frank van Puffelen
Mar 23 at 23:24
add a comment |
Answer below. Since this may indeed not work for you, you might want to explain what you're trying to accomplish here. As it stands your question reads like a XY problem, and if we know the actual goal we may be able to come up with an alternative approach.
– Frank van Puffelen
Mar 23 at 23:24
Answer below. Since this may indeed not work for you, you might want to explain what you're trying to accomplish here. As it stands your question reads like a XY problem, and if we know the actual goal we may be able to come up with an alternative approach.
– Frank van Puffelen
Mar 23 at 23:24
Answer below. Since this may indeed not work for you, you might want to explain what you're trying to accomplish here. As it stands your question reads like a XY problem, and if we know the actual goal we may be able to come up with an alternative approach.
– Frank van Puffelen
Mar 23 at 23:24
add a comment |
1 Answer
1
active
oldest
votes
The Firebase Realtime Database does not track the position of nodes in their parents, nor does it return such a position in query results. This means the only way to determine the position of a child within a set of child nodes, is to retrieve all child nodes before the one you're looking for.
.ref("users")
.orderByChild("email")
.endAt(myEmail)
.once("value", snapshot =>
var index = 0;
snapshot.forEach(function(childNode)
if (childNode.child("email").val() === myEmail)
console.log("Database Position", index);
else
index = index + 1;
);
Since you commented that you're trying to create a leaderboard, see:
- Leaderboard ranking with Firebase
- Unity - Firebase realtime database - Get my rank in leaderboard
- Getting rank of user from firebase database in android
Thanks Frank, this is unfortunate. I have a list of >1k users that are ranked (by 'Score'). I was hoping I could use the position in the database to use as their rank. I suppose the best method would be to run a firebase function once per day to update a rank field.
– gvon79
Mar 24 at 13:37
I added links to some previous answer about leaderboards and ranking.
– Frank van Puffelen
Mar 24 at 14:21
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55318674%2fhow-to-get-the-position-of-an-item-in-the-realtime-database%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The Firebase Realtime Database does not track the position of nodes in their parents, nor does it return such a position in query results. This means the only way to determine the position of a child within a set of child nodes, is to retrieve all child nodes before the one you're looking for.
.ref("users")
.orderByChild("email")
.endAt(myEmail)
.once("value", snapshot =>
var index = 0;
snapshot.forEach(function(childNode)
if (childNode.child("email").val() === myEmail)
console.log("Database Position", index);
else
index = index + 1;
);
Since you commented that you're trying to create a leaderboard, see:
- Leaderboard ranking with Firebase
- Unity - Firebase realtime database - Get my rank in leaderboard
- Getting rank of user from firebase database in android
Thanks Frank, this is unfortunate. I have a list of >1k users that are ranked (by 'Score'). I was hoping I could use the position in the database to use as their rank. I suppose the best method would be to run a firebase function once per day to update a rank field.
– gvon79
Mar 24 at 13:37
I added links to some previous answer about leaderboards and ranking.
– Frank van Puffelen
Mar 24 at 14:21
add a comment |
The Firebase Realtime Database does not track the position of nodes in their parents, nor does it return such a position in query results. This means the only way to determine the position of a child within a set of child nodes, is to retrieve all child nodes before the one you're looking for.
.ref("users")
.orderByChild("email")
.endAt(myEmail)
.once("value", snapshot =>
var index = 0;
snapshot.forEach(function(childNode)
if (childNode.child("email").val() === myEmail)
console.log("Database Position", index);
else
index = index + 1;
);
Since you commented that you're trying to create a leaderboard, see:
- Leaderboard ranking with Firebase
- Unity - Firebase realtime database - Get my rank in leaderboard
- Getting rank of user from firebase database in android
Thanks Frank, this is unfortunate. I have a list of >1k users that are ranked (by 'Score'). I was hoping I could use the position in the database to use as their rank. I suppose the best method would be to run a firebase function once per day to update a rank field.
– gvon79
Mar 24 at 13:37
I added links to some previous answer about leaderboards and ranking.
– Frank van Puffelen
Mar 24 at 14:21
add a comment |
The Firebase Realtime Database does not track the position of nodes in their parents, nor does it return such a position in query results. This means the only way to determine the position of a child within a set of child nodes, is to retrieve all child nodes before the one you're looking for.
.ref("users")
.orderByChild("email")
.endAt(myEmail)
.once("value", snapshot =>
var index = 0;
snapshot.forEach(function(childNode)
if (childNode.child("email").val() === myEmail)
console.log("Database Position", index);
else
index = index + 1;
);
Since you commented that you're trying to create a leaderboard, see:
- Leaderboard ranking with Firebase
- Unity - Firebase realtime database - Get my rank in leaderboard
- Getting rank of user from firebase database in android
The Firebase Realtime Database does not track the position of nodes in their parents, nor does it return such a position in query results. This means the only way to determine the position of a child within a set of child nodes, is to retrieve all child nodes before the one you're looking for.
.ref("users")
.orderByChild("email")
.endAt(myEmail)
.once("value", snapshot =>
var index = 0;
snapshot.forEach(function(childNode)
if (childNode.child("email").val() === myEmail)
console.log("Database Position", index);
else
index = index + 1;
);
Since you commented that you're trying to create a leaderboard, see:
- Leaderboard ranking with Firebase
- Unity - Firebase realtime database - Get my rank in leaderboard
- Getting rank of user from firebase database in android
edited Mar 24 at 14:20
answered Mar 23 at 23:22
Frank van PuffelenFrank van Puffelen
253k31407435
253k31407435
Thanks Frank, this is unfortunate. I have a list of >1k users that are ranked (by 'Score'). I was hoping I could use the position in the database to use as their rank. I suppose the best method would be to run a firebase function once per day to update a rank field.
– gvon79
Mar 24 at 13:37
I added links to some previous answer about leaderboards and ranking.
– Frank van Puffelen
Mar 24 at 14:21
add a comment |
Thanks Frank, this is unfortunate. I have a list of >1k users that are ranked (by 'Score'). I was hoping I could use the position in the database to use as their rank. I suppose the best method would be to run a firebase function once per day to update a rank field.
– gvon79
Mar 24 at 13:37
I added links to some previous answer about leaderboards and ranking.
– Frank van Puffelen
Mar 24 at 14:21
Thanks Frank, this is unfortunate. I have a list of >1k users that are ranked (by 'Score'). I was hoping I could use the position in the database to use as their rank. I suppose the best method would be to run a firebase function once per day to update a rank field.
– gvon79
Mar 24 at 13:37
Thanks Frank, this is unfortunate. I have a list of >1k users that are ranked (by 'Score'). I was hoping I could use the position in the database to use as their rank. I suppose the best method would be to run a firebase function once per day to update a rank field.
– gvon79
Mar 24 at 13:37
I added links to some previous answer about leaderboards and ranking.
– Frank van Puffelen
Mar 24 at 14:21
I added links to some previous answer about leaderboards and ranking.
– Frank van Puffelen
Mar 24 at 14:21
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55318674%2fhow-to-get-the-position-of-an-item-in-the-realtime-database%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Answer below. Since this may indeed not work for you, you might want to explain what you're trying to accomplish here. As it stands your question reads like a XY problem, and if we know the actual goal we may be able to come up with an alternative approach.
– Frank van Puffelen
Mar 23 at 23:24