I am stuck in one case of firebase operation in android. My Requirement :
I have table Named : "Values" This value table contains following type of data.
{
"menu": [
{
"category": "cocktails",
"product": [
{
"id": "123",
"name": "test1"
},
{
"id": "456",
"name": "test2"
}
]
},
{
"category": "vodka",
"product": [
{
"id": "789",
"name": "test3"
},
{
"id": "901",
"name": "test4"
}
]
}
]
}
Now, I want to update id : 123 with name = "test5" , How to update this nested array object in firebase database in android?
I tried following but it update/add Entire menu array not perticular product array object.
I just want to update in product array object.
Following are the code that i tried, but it update all menu array.
val listPorduct = ArrayList<HashMap<String, Any>>()
for ((i, product) in productList.withIndex()) {
var productMap = HashMap<String, Any>()
productMap = hashMapOf(
"id" to "123",
"name" to "test5")
listPorduct.add(productMap)
}
val map = hashMapOf<String, Any>()
map.put("category", list[position].category)
map.put("product", listPorduct)
repository.getTabs().update("menu", FieldValue.arrayUnion(map))
if i am try with
repository.getTabs().update("menu/product", FieldValue.arrayUnion(map))
or
repository.getTabs().update("menu.product", FieldValue.arrayUnion(map))
then getting issue / or dot not allowed. i have latest firebase gradle file.
How update particular position of product object? Please anyone can help me to solve out this?
Image of firebase database.