Vì vậy, tôi có dữ liệu như sau:Tại sao Firebase ".indexOn" này không hoạt động?
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
}
}
Trong mã của tôi, tôi cần phải nhận được thông báo mới nhất dưới đây để một "notifyId" nhất định. Đây là mã:
ref.child('pushNotifications')
.orderByChild("notifyId")
.limitToLast(1)
.on("child_added", function (snapshot) {
console.log("Found a new notification...");
sendPush(snapshot.val());
});
Trong quy tắc an ninh căn cứ hỏa lực của tôi, tôi có nguyên tắc chỉ số này:
"pushNotifications": {
".read": "auth != null",
".write": "auth != null",
"$pushId": {
".indexOn": ["notifyId", "timestamp"],
}
},
Đây là theo cấu trúc chỉ mục bằng các tài liệu căn cứ hỏa lực ở đây: docs
Nhưng khi Tôi chạy mã, bảng điều khiển vẫn đăng nhập
FIREBASE CẢNH BÁO: Sử dụng chỉ mục không xác định. Xem xét thêm ".indexOn": "notifyId" tại/pushNotifications vào các quy tắc bảo mật của bạn để có hiệu suất tốt hơn
Điều này không có ý nghĩa gì kể từ khi tôi làm điều đó. Hãy giúp tôi!
Btw, chủ đề tương tự này đã được giải quyết ít hơn một ngày trước đây tại đây: htt p: //stackoverflow.com/questions/32849805/firebase-index-rule-for-attributes-under-key-created-by-childautobyid –