[英]FirebaseException in ref.updateChildren(): Path X is an ancestor of X/Y in an update
When trying to perform a multi-path write using path like " users/user
" and " users/user/name
" in the same ref.updatChildren()
operation, app crashes with the following exception: 尝试在同一ref.updatChildren()
操作中使用“ users/user
”和“ users/user/name
”之类的路径执行多路径写入时,应用程序崩溃时出现以下异常:
com.firebase.client.FirebaseException: Path X is an ancestor of X/Y in an update. com.firebase.client.FirebaseException:路径X是更新中X / Y的祖先。
What is the best way to perform this kind of multi-path writes in Firebase? 在Firebase中执行此类多路径写入的最佳方法是什么? Thanks! 谢谢!
EDIT : In this particular case I wanted to achieve something like: 编辑 :在这个特殊情况下,我希望实现以下目标:
HashMap<String, Object> userUpdate = new HashMap<String, Object>();
HashMap<String, String> user = new HashMap<String, String>();
user.put("firstName", "Ivan");
user.put("initialOfLastName", "V");
userUpdate.put("/user", user);
userUpdate.put("/user/gender", "male")
ref.updateChildren(userUpdate);
Like the error states, you can't specify an update for /user
and then specify a different update for /user/gender
. 与错误状态一样,您无法为/user
指定更新,然后为/user/gender
指定其他更新。 Moving the gender update to the user
map should work. 将性别更新移动到user
地图应该有效。
user.put("firstName", "Ivan");
user.put("initialOfLastName", "V");
user.put("gender", "male")
userUpdate.put("/user", user);
ref.updateChildren(userUpdate);
For cases like that, you'll have to use a nested HashMap
at the top-level of the location you're updating. 对于这种情况,您必须在要更新的位置的顶层使用嵌套的HashMap
。
HashMap<String,String> userUpdate = new HashMap<String,String>();
userUpdate.put("firstName", "Ivan");
userUpdate.put("initialOfLastName", "V");
ref.child(uid).updateChildren(userUpdate);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.