0

I am trying to add the ability to update the document name inside of my usernames collection inside my Flutter app. Here is my upload function:

    Future<void> updateUsername() {
      // Add a new user inside our the Usernames Collection. This is useful to check for username availablilty.
      return usernames
          .doc(username)
          .set({
            'uid': uid,
            'timeCreated': DateTime.now(),
          })
          .then((value) => print("Username Added"))
          .catchError((error) => print("Failed to add username: $error"));
    }

Here is my database setup: enter image description here

DB Cooper
  • 63
  • 1
  • 9

1 Answers1

1

There is no option in firestore to rename a document. The way the most uses is to create a new document with the new name and the data that been in the old document, then delete the old document.
Take a look here: Can I change the name of a document in Firestore?

One more advice, if you're not going to put any data in the usernames documents, then make a document that has the name "usernames" and add them there, that would help to make less reads ... unless you know what you're doing.

Remoo
  • 637
  • 7
  • 17
  • thanks. In terms of my database setup, it has to be set up like this but yeah it will cause more reads and writes. – DB Cooper Dec 01 '21 at 22:52