2017-10-05 69 views
0

我使用以下代碼從firebase數據庫中刪除某些數據庫對象。但是,由於某些原因,.remove()並沒有刪除數據庫對象,並且出乎意料地沒有引發錯誤,並且.then()也在執行。有人可以幫我嗎?Firebase .remove無法正常工作;沒有錯誤返回

try { 
    db1.ref('statements/' + nodeLocation).remove() 
     .then(function() { 
      console.log ("nodeLocation[" + i + "] " + nodeLocation + " deleted successfully! "); 
     }, (err) => {console.log(err)}); 
} catch (err) { 
    console.log ("Error while deleting!"); 
    console.log (err); 
    console.log("Error:" + err.error_message); 
} 
+0

顯示您的firebase數據模型。 – Hareesh

+0

@Hareesh感謝您回覆,但我認爲這是一個參考問題,並按照我在下面的答案中所述進行了修復。 –

回答

0

我想通了。上面的代碼沒有問題,但是,由於'nodeLocation'已經包含'statements /'並且上面的代碼再次加了前綴,所以引用不正確。因此,簡單地更換這行代碼:

db1.ref('statements/' + nodeLocation).remove() 

這一個:

db1.ref(nodeLocation).remove() 

工作!

相關問題