Why does this Firebase ".indexOn" not work? -
so have data so:
pushnotifications { -k - rwegd541pignoxxuh: { message: "xiaoyu hugh hou bid @ $900 on task: new p..." notifyid: "facebook:10100683829966199" relatedtask: "-jzl8xkaxgcv19niochm" timestamp: 1443594566599 } - k - rwpcblqa04vjt4bwm: { message: "sam feldt bid @ $1100 on task: new post g..." notifyid: "google:1043268349966197" relatedtask: "-jzl8xkaxgcv19niochm" timestamp: 1443594721963 } - k - rwum3 - 0 g0q9i96whg: { message: "sam feldt bid @ $600 on task: no firebase..." notifyid: "facebook:10100683829966199" relatedtask: "-jztsk2tilo46ovqj1nn" timestamp: 1443594741347 } }
in code, need latest notification below "notifyid". here code:
ref.child('pushnotifications') .orderbychild("notifyid") .limittolast(1) .on("child_added", function (snapshot) { console.log("found new notification..."); sendpush(snapshot.val()); });
in firebase security rule, have index rule:
"pushnotifications": { ".read": "auth != null", ".write": "auth != null", "$pushid": { ".indexon": ["notifyid", "timestamp"], } },
it index structure follow firebase docs here: docs
but when run code, console still log
firebase warning: using unspecified index. consider adding ".indexon": "notifyid" @ /pushnotifications security rules better performance
which not make sense since did already. please help!
you need put .indexon
1 level higher did:
"pushnotifications": { ".read": "auth != null", ".write": "auth != null", ".indexon": ["notifyid", "timestamp"] },
for comparison @ firebase documentation on indexes, uses json example:
"dinosaurs": { "lambeosaurus": { "height" : 2.1, "length" : 12.5, "weight": 5000 }, "stegosaurus": { "height" : 4, "length" : 9, "weight" : 2500 } }
with indexing rule:
{ "rules": { "dinosaurs": { ".indexon": ["height", "length"] } } }
Comments
Post a Comment