Home > Net >  Cloud firestore: How to create and update a nested array with map object
Cloud firestore: How to create and update a nested array with map object

Time:02-04

I want to create/update a set of data in the cloud firestore in that is stored in a nested array method.

enter image description here I want to define the nested array to be in a Map<String, dynamic> method like this.

CodePudding user response:

First, you have to create instance of categories model then change the value according to your requirement

for ex:

 Categories c =  categories; // here assign your exiting data of categories
     c.copyWith(flavor : ["hello","world"]);

          await FirebaseFirestore.instance
          .collection('user')
          .doc(FirebaseAuth.instance.currentUser?.uid)
          .collection('todos')
          .doc(map["collectionId"])
          .update(FieldValue.arrayUnion(c)))
  • Related