2017-01-12 17 views
2

,我有以下數據開始:火力地堡查詢不將數據推然後重新添加

"holidays": { 
    ... 
    "2016-12-19": { 
     "stegosaurus": true 
    }, 
    "2016-12-20": { 
     "lambeosaurus": true, 
     "stegosaurus": true 
    }, 
    "2016-12-21": { 
     "lambeosaurus": true 
    }, 
    ... 
    } 

用下面的查詢,

ref.orderByKey().startAt("2016-12-18") 
       .endAt("2016-12-18") 
       .on("child_added", function(snapshot) { 
        console.log("child_added") 
       }); 
ref.orderByKey().startAt("2016-12-18") 
       .endAt("2016-12-18") 
       .on("child_removed", function(snapshot) { 
        console.log("child_removed") 
       }); 
ref.orderByKey().startAt("2016-12-18") 
       .endAt("2016-12-18") 
       .on("child_changed", function(snapshot) { 
        console.log("child_changed") 
       }); 
ref.orderByKey().startAt("2016-12-18") 
       .endAt("2016-12-18") 
       .on("child_moved", function(snapshot) { 
        console.log("child_moved") 
       }); 

在初始添加新節點「 2016-12-18「到」節假日「節點,我收到了一個child_added事件。當節點「2016-12-18」被刪除時,我得到一個child_removed事件。但是當我加回「2016-12-18」時,這次我沒有收到任何事件。這是一個firebase錯誤?

下面是複製這個問題jsbin: https://jsbin.com/sefaha/6/edit?html,console,output

重現:

1) On reload, Click Update button 
2) Dino info is displayed 
3) Click Delete button 
4) Dino info is removed 
5) Click Update button 
6) Dino info is not displayed anymore 
7) Reload/refresh browser 
8) Dino info is displayed 
9) Click Delete button 
10) Repeat step (1) 

請注意,在步驟(1),不顯示有時迪諾信息。這似乎取決於連接的客戶端的數量。

+0

您分享的代碼實際上並沒有添加數據,因此很難確定。但總的來說,Firebase SDK的這一部分現在已經相當穩定了。總是有可能存在錯誤,在這種情況下,我很想看到[MCVE](http://stackoverflow.com/help/mcve)。如果你可以設置一個可以重現問題的jsbin,它通常會很有幫助嗎? –

+0

@FrankvanPuffelen我用jsbin更新了這個問題來複制問題。感謝您查看這個。 – user3240644

+0

感謝tje jsbin。它使用PolymerFire,而您的原始問題基於純粹的Firebase JavaScript SDK。鑑於我對PolymerFire的內部工作不熟悉(我真的應該更多地瞭解它,但今天不是那一天),您是否可以通過JavaScript SDK重現問題? –

回答

1

使用深度更新重新添加先前在同一會話中刪除的節點時確實存在一個錯誤。它一直隱藏在火力地堡數據庫服務器相當長的一段時間,可以在這個片段被複制:

var query = ref.orderByKey().startAt("2017-01-13").endAt("2017-01-13"); 
// attaching this listener makes it work 
//ref.on("value", function(s) { console.log("value", s.val())}); 
query.on("child_added", function(snapshot) { console.log("child_added"); }); 
query.on("child_removed", function(snapshot) { console.log("child_removed"); }); 
query.on("child_changed", function(snapshot) { console.log("child_changed"); }); 
query.on("child_moved", function(snapshot) { console.log("child_moved"); }); 
function _update() { 
    console.log("updating child"); 
    ref.update({'2017-01-13/-KaMFzShw40MkBtMypUg': true }); 
    // using this way of setting the value makes it work 
    //ref.child('2017-01-13/-KaMFzShw40MkBtMypUg').set(true); 
}; 
function _delete() { 
    console.log("deleting child"); 
    ref.update({'2017-01-13/-KaMFzShw40MkBtMypUg': null}); 
}; 

完全jsbin:https://jsbin.com/zedojum/edit?html,console,output

您可以解決的錯誤使用set()而不是更新直接升級較低級別的子級,或者通過將偵聽程序附加到該位置(而不是查詢)。

我會在這裏發佈說明,當它被修復。

+0

對我來說,這看起來還是破了。我爲此編寫了一些單元測試,並發現查詢引用上的事件偵聽器似乎只觸發一次,除非同一個鍵上的非查詢引用上也有偵聽器。我會馬上提交一個錯誤報告。 – cartant

+0

@cartant太好了!你能不能讓我更新錯誤報告的進展?謝謝! – user3240644

+0

剛剛提交了錯誤報告*「[7-3405000015569]查詢ref偵聽器有時只觸發一次」*。 – cartant