0
授權後,我在表「用戶」中添加用戶。此外,我還會爲此用戶添加一些值,我不希望被忽略。如何禁止重寫數據(如果存在的話)
ref.child("users").child((FIRAuth.auth()?.currentUser?.uid)!).setValue(["username": "MyName"])
規則
{
"rules": {
".read": "auth != null",
".write": "auth != null",
"users": {
".write": "!root.child('users/'+auth.uid).exists()",
".read":true,
"positive": {
".read": true,
".write":false,
},
"negative": {
".read": true,
".write":false,
},
}
}
}
刪除舊數據,換上新的。
我想在服務器端寫規則,如果它已經存在,將忽略設置值。
這是否防止被寫入到數據已經存在的節點數據? – Jay
不是。這將是'!data.exists()'。 –
很奇怪,我們無法控制服務器端的數據。是的,你的解決方案正在工作。不是我想要的,而是讓它成爲。 –