1

Current data in firestore

fruits: { apple: 20, orange: 10 }

Now how to add more fruits to the fruits field without overwriting apple and orange

Fruits to be added

fruits: { pineapple: 20, cherry: 10, banana: 10 }

Tried doing this but apple and orange gets removed

batch.update(fs.doc(`config/254868`), {
  fruits: fruits,
});
Dharmaraj
  • 47,845
  • 8
  • 52
  • 84
Ibrahim Ali
  • 2,083
  • 2
  • 15
  • 36
  • 2
    You need to use [dot notation](https://firebase.google.com/docs/firestore/manage-data/add-data#update_fields_in_nested_objects) to call out each individual nested field to update. What you are doing right now is specifying an entirely new map to update the field called "fruits". – Doug Stevenson Jun 03 '22 at 15:44

0 Answers0