I'm trying to lazy load firebase items to later on load more of them whenever user reaches end of div container. When i remove .endAt()
and .startAt()
i'm receiving the 15 items though they are not beeing incremented and it's stuck at these 15 items.
When i keep .endAt()
and .startAt()
i'm receiving firebase warning
Using an unspecified index. Consider adding ".indexOn": "title" at /items
even though .indexOn
is set. I'm confused by that warning. Thanks in advance for any help.
Firebase structure
{
"items" : {
"-Kk6aHXIyR15XiYh65Ht" : {
"author" : "joe",
"title" : "Product 1"
},
"-Kk6aMQlh6_E3CJt_Pnq" : {
"author" : "joe",
"title" : "Product 2"
}
},
"users" : {
"RG9JSm8cUndpjMfZiN6c657DMIt2" : {
"items" : {
"-Kk6aHZs5xyOWM2fHiPV" : "-Kk6aHXIyR15XiYh65Ht",
"-Kk6aMTJiLSF-RB3CZ-2" : "-Kk6aMQkw5bLQst81ft7"
},
"uid" : "RG9JSm8cUndpjMfZiN6c657DMIt2",
"username" : "joe"
}
}
}
Security rules
{
"rules": {
".read": true,
".write": "auth != null",
"users":{
"$uid": {
".write": "$uid === auth.uid"
"items":{
".indexOn": "title",
"$itemId": {
"title": {".validate": "...}
"type": {".validate": "...}
}
}
}
}
}
}
}
Code structure for lazy load
let _start = 0,
_end = 14,
_n = 15;
function lazyLoadItems(){
firebase.database().ref('items')
.orderByChild('title')
.startAt(_start)
.endAt(_end)
.limitToFirst(_n)
.on("child_added", snapshot=> console.log(snapshot.val()));
_start += _n;
_end += _n;
}
/items
, while you added an index to/users/$uid/items
./users/$uid/items
withoutuid
won't do the job. And adding.indexOn('items')
in"rules"
doesn't make sense. Could it be badly structured rules then?items
===decks
. pastebin.com/wskVaNPy/items
in there. Please provide a single MCVE (read the link on why this is a more efficient way to get help than the back-and-forth we've been having).