I've attempted to work with the Firebase (2.2.5) API / .orderByChild('score') operation and I keep getting
No index defined for score
Although documentation of Firebase states I don't need to create an index for score when using the WebSocket API, I did create it. Markup:
Rules
{
"rules": {
".read": false,
".write": false,
/* index players by score */
"Players": {
".read": true,
".indexOn": "score",
"$playerID": {
".write": "!data.exists() || data.child('uid').val() === auth.uid"
}
}
}
}
Data
{
"Players": {
"-JpqOuoaHmcA2EngEvSZ" : {
".priority" : 0.0,
"avatar" : "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRS9Yh2lWzGP1oojIwNVV2JQUZYFX4_4pxvaADz8TfDF_WGrHbs",
"draw" : 9,
"lastTimeAccessed" : 1432705280027,
"lost" : 7,
"name" : "Hans",
"score" : 126,
"won" : 36
},
"-JpzVTpXZUZG-V0qJCDT" : {
".priority" : 2.0,
"avatar" : "http://static.wixstatic.com/media/6a9a03_f979928a006c4d2ebc179c1c627dc119.png_srz_300_300_75_22_0.50_1.20_0.00_png_srz",
"draw" : 0,
"lastTimeAccessed" : 1432705280532,
"lost" : 25,
"name" : "Safari",
"score" : 9,
"won" : 3
}
}
}
Calling
I have a Firebase() object pointed at http://theapp.firebaseio.com/Players for which I am calling orderByChild('score'). I would expect this to work.
Looking forward to some fresh views or tips.
I ran into this error when using this code:
const snap = await admin
.database()
.ref("keepAlive")
.orderByChild("lastSeen")
.get();
snap.forEach((result) => {
console.log({ result });
});
Changing the code to this makes it work:
const snap = await admin
.database()
.ref("keepAlive")
.orderByChild("lastSeen")
.once("value");
snap.forEach((result) => {
console.log({ result: result.val() });
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With