Home > Enterprise >  editing document and field in firebase
editing document and field in firebase

Time:10-24

im working on firebase and im trying to update the document name and its field name together like shown in the image. i want them to be updated together.

enter image description here

i used this code

    EditCourse(String cName, String newName) async {
  var collection = FirebaseFirestore.instance.collection("Courses")
    ..where("Course name", isEqualTo: cName);
  collection.doc(cName).update({'Course name': newName});
}

CodePudding user response:

Answer: As of Now Firebase not allows to update documents ids)

Suggestion: You should use relational ids or random ids (relational ids means suppose you have seller favorite collection you can give documents ids to movie/food ids)

CodePudding user response:

There is no way to update the document ID of an existing document. If changing course names is a use-case you need to support, consider using Firestore's built-in ID generation when adding your documents (so add documents using the add() method).

If you stick to your current model, you'll have to:

  1. Read the existing document.
  2. Write the date under the new ID.
  3. Delete the original document.

Given the type of operation, you'll probably want to use a transaction for that.

  • Related