How do I add multiple values for the same key in Firebase? When I do the following to add data to my database, the objects are just replacing each other.
Map<String,Object> taskMap = new HashMap<>();
taskMap.put("age", "12");
taskMap.put("gender", "male");
taskMap.put("age", "45");
taskMap.put("gender", "female");
reference.setValue(taskMap);
The data in Firebase only displayed age 45, and gender female. It overrode the age 12 and gender male. How do I have both?
To update a subset of the existing properties or to add new ones, use updateChildren():
Map<String,Object> taskMap = new HashMap<>();
taskMap.put("age", "12");
taskMap.put("gender", "male");
taskMap.put("age", "45");
taskMap.put("gender", "female");
reference.updateChildren(taskMap);
Also see the documentation for updating specific fields.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With