2015-09-30 27 views
7

Yani şöyle veri var: Benim kodBu Firebase ".indexOn" neden çalışmıyor?

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 
    } 
} 

, ben belirli bir "notifyId" Aşağıdaki son bildirim almak gerekir. İşte kod: docs

Ama:

"pushNotifications": { 
     ".read": "auth != null", 
     ".write": "auth != null", 
     "$pushId": { 
     ".indexOn": ["notifyId", "timestamp"], 
     } 
    }, 

Burada Firebase docs tarafından indeks yapısı takip geçerli: Benim Firebase güvenlik kuralı olarak

ref.child('pushNotifications') 
    .orderByChild("notifyId") 
    .limitToLast(1) 
    .on("child_added", function (snapshot) { 
     console.log("Found a new notification..."); 
     sendPush(snapshot.val()); 
    }); 

, bu endeks kuralı var Kodu çalıştırıyorum, konsolu hala oturum açın

YANGIN BAZI UYARI: Belirtilmemiş bir dizin kullanılmalıdır. Daha iyi performans için güvenlik kurallarınıza ".indexOn": "notifyId" ekleyerek "pushifyId" ifadesini ekleyiniz.

Zaten bunu yaptığımdan beri bir anlam ifade etmiyor. Lütfen yardım et!

+0

Btw, bu aynı konu bir günden daha önce şu adreste ele alındı: htt s: //stackoverflow.com/questions/32849805/firebase-index-rule-for-attributes-under-key-created-by-childautobyid –

cevap

23

Ne yaptığını daha .indexOn bir seviye daha yüksek koymak gerekir:

"pushNotifications": { 
    ".read": "auth != null", 
    ".write": "auth != null", 
    ".indexOn": ["notifyId", "timestamp"] 
}, 

Karşılaştırma için her zaman bu JSON örneği kullanır Firebase documentation on indexes bakmak: Bu endeksleme kuralıyla

"dinosaurs": { 
    "lambeosaurus": { 
    "height" : 2.1, 
    "length" : 12.5, 
    "weight": 5000 
    }, 
    "stegosaurus": { 
    "height" : 4, 
    "length" : 9, 
    "weight" : 2500 
    } 
} 

:

{ 
    "rules": { 
    "dinosaurs": { 
     ".indexOn": ["height", "length"] 
    } 
    } 
}