ref.updateChildren()中的FirebaseException:路径X是更新中X/Y的祖先 [英] FirebaseException in ref.updateChildren(): Path X is an ancestor of X/Y in an update
问题描述
当尝试在同一 ref中使用"
操作,应用崩溃,但出现以下异常: users/user
"和" users/user/name
"之类的路径执行多路径写入时.updatChildren()
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:
com.firebase.client.FirebaseException:路径X是X/Y的祖先更新.
com.firebase.client.FirebaseException: Path X is an ancestor of X/Y in an update.
在Firebase中执行这种多路径写入的最佳方法是什么?谢谢!
What is the best way to perform this kind of multi-path writes in 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);
推荐答案
像错误状态一样,您不能为/user
指定更新,然后为/指定其他更新用户/性别
.将性别更新移动到 user
地图应该可以.
Like the error states, you can't specify an update for /user
and then specify a different update for /user/gender
. Moving the gender update to the user
map should work.
user.put("firstName", "Ivan");
user.put("initialOfLastName", "V");
user.put("gender", "male")
userUpdate.put("/user", user);
ref.updateChildren(userUpdate);
这篇关于ref.updateChildren()中的FirebaseException:路径X是更新中X/Y的祖先的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!