如何在 firebase 的一个请求中删除多个节点?
How to delete multiple nodes in one request in firebase?
我有两个来自一个根的节点,我想在一个请求中删除它们的数据。两个子节点具有相同的密钥。我试过这个:
Firebase firebaseRef = new Firebase(<root_path>);
Map<String, Object> childUpdates = new HashMap<>();
childUpdates.put(<path_to_first_node>, key);
childUpdates.put(<path_to_second_node>, key);
listToRemoveRef.updateChildren(childUpdates, null);
但它只删除了第一个节点的数据
看来您使用的 updateChildren
函数有误。你要做的是这个
Firebase firebaseRef = new Firebase(<root_path>);
Map<String, Object> childUpdates = new HashMap<>();
childUpdates.put("<path_to_first_node>" + key, null);
childUpdates.put("<path_to_second_node>" + key, null);
listToRemoveRef.updateChildren(childUpdates);
updateChildren
的第二个参数没有将值设置为 null
它是一个可选的完成侦听器 (see documentation)。因此,与其在最后一行将 null
传递给它,不如省略它。
我有两个来自一个根的节点,我想在一个请求中删除它们的数据。两个子节点具有相同的密钥。我试过这个:
Firebase firebaseRef = new Firebase(<root_path>);
Map<String, Object> childUpdates = new HashMap<>();
childUpdates.put(<path_to_first_node>, key);
childUpdates.put(<path_to_second_node>, key);
listToRemoveRef.updateChildren(childUpdates, null);
但它只删除了第一个节点的数据
看来您使用的 updateChildren
函数有误。你要做的是这个
Firebase firebaseRef = new Firebase(<root_path>);
Map<String, Object> childUpdates = new HashMap<>();
childUpdates.put("<path_to_first_node>" + key, null);
childUpdates.put("<path_to_second_node>" + key, null);
listToRemoveRef.updateChildren(childUpdates);
updateChildren
的第二个参数没有将值设置为 null
它是一个可选的完成侦听器 (see documentation)。因此,与其在最后一行将 null
传递给它,不如省略它。