Nitin Gopal
Nitin Gopal

Reputation: 31

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

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.

Upvotes: 2

Views: 292

Answers (1)

Rahul Variya
Rahul Variya

Reputation: 1352

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)))

Upvotes: 2

Related Questions