skip to Main Content

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

Specifically in Flutter.

2

Answers


  1. Update a document won’t overwrite your subcollection.

    Login or Signup to reply.
  2. 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/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search