in my flutter app i need to create a new document and create and set value to a newfield in firestore,when the user creates an account. when user creates his account i call await Database().updateusername(email); which is
Future updateusername(String username) async {
final DocumentReference Docreference =
FirebaseFirestore.instance.collection("Songs").doc(username);
return await Docreference.update({"Username": username});
}
but i get this error
cloud_firestore/not-found] Some requested document was not found.
my firestore version is ^0.14.0+2
can someone help me on this issue
The error message is telling you that the document you build a reference to was not found for update. You can't update() a document that doesn't exist. According to that linked API documentation:
If no document exists yet, the update will fail.
If you want to create a document if it doesn't exist, you will need to use set() instead of update. If you want to be able to create a document if it doesn't exist, or update it if it does already exist, you should pass SetOptions.merge as the second parameter, as explained by the API documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With