7
所以我有數據,像這樣:爲什麼Firebase「.indexOn」不起作用?
pushNotifications {
-K - RwEgd541PIGNOXXUH: {
message: "Xiaoyu Hugh Hou bid at $900 on your task: New P..."
notifyId: "facebook:10100683829966199"
relatedTask: "-Jzl8XKaxGCv19nIOChm"
timestamp: 1443594566599
} - K - RwpcBlQa04VJT4Bwm: {
message: "Sam Feldt bid at $1100 on your task: New Post g..."
notifyId: "google:1043268349966197"
relatedTask: "-Jzl8XKaxGCv19nIOChm"
timestamp: 1443594721963
} - K - RwuM3 - 0 G0q9I96WHg: {
message: "Sam Feldt bid at $600 on your task: NO Firebase..."
notifyId: "facebook:10100683829966199"
relatedTask: "-JzTSk2TIlO46oVqJ1Nn"
timestamp: 1443594741347
}
}
在我的代碼,我需要得到下面一定的「notifyId」的最新通知。下面是代碼:
ref.child('pushNotifications')
.orderByChild("notifyId")
.limitToLast(1)
.on("child_added", function (snapshot) {
console.log("Found a new notification...");
sendPush(snapshot.val());
});
在我火力安全規則,我有這樣的指數規則:
"pushNotifications": {
".read": "auth != null",
".write": "auth != null",
"$pushId": {
".indexOn": ["notifyId", "timestamp"],
}
},
這是該指數結構遵循由火力地堡文檔瀏覽:docs
但是,當我運行的代碼,控制檯仍然日誌
FIREBASE警告:使用未指定的索引。考慮在/ pushNotifications處添加「.indexOn」:「notifyId」到您的安全規則以獲得更好的性能
由於我已經做到了,所以沒有任何意義。請幫忙!
順便說一句,這個相同的主題是不到一天前在這裏解決:htt電話號碼://stackoverflow.com/questions/32849805/firebase-index-rule-for-attributes-under-key-created-by-childautobyid –