0

Have a json structure as follows. How can an element/the marks section be updated?

Have tried using arrayUnion approach, by passing a list/hashmap of Mark object. But did not work.

saw an example https://medium.com/@thilanka.nuwan89/cloud-firestore-updating-object-arrays-be6ded13e76f

but could not figure out a way to achieve this in Java.

student {
 "id" : "1122",
 "marks" [{
   "physics" : "95",
   "maths" : "98"
 }]
}

To be able to update the marks section completely/partially.

programmer
  • 249
  • 4
  • 12
  • Please add your database structure as a screenshot. – Alex Mamo Nov 07 '19 at 16:59
  • passing the above json as such to firestore. – programmer Nov 07 '19 at 17:06
  • If you want to get helped, please add the screenshot I have asked you. – Alex Mamo Nov 07 '19 at 17:12
  • only have access through APIs. yet to get the console access – programmer Nov 07 '19 at 17:39
  • There is no syntax for updating an array by index. You have to read the document, make change to the array in memory, then udpate the document with the new data. – Doug Stevenson Nov 07 '19 at 20:30
  • db.collection(TARGET_COLLECTION).doc(newLocation.hostId).update({ locations: admin.firestore.FieldValue.arrayRemove({ id: locationId, name: oldLocation.name, description: oldLocation.description }) }) As mentioned in the link, how is the above logic implemented in Java? { id: locationId, name : location.name }. Have tried List, Map. – programmer Nov 08 '19 at 02:07
  • The question is not about updating an array by index. It is about updating an array of objects. Please do not close this question. – programmer Nov 09 '19 at 06:05

0 Answers0