简体   繁体   中英

in firebase firestore how can I update a document without overwriting subcollections?

How can I update a document in Firebase Firestore without overwriting subcollections?

Specifically in Flutter.

Update a document won't overwrite your subcollection.

Just set your documents fields directly:

    FirebaseFirestore.instance
          .collection(COLLECTION_NAME)
          .doc(DOCUMENT_ID)
          .set({ "FIELD_NAME": "FIELD_VALUE" });

This will not affect the document collections.

If you want to just update some fields without affect other fields, you can use update method:

 FirebaseFirestore.instance
          .collection(COLLECTION_NAME)
          .doc(DOCUMENT_ID)
          .update({ "FIELD_NAME": "FIELD_VALUE" });

For further information:

https://firebase.flutter.dev/docs/firestore/usage/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM