Stream closed with status: Status{code=NOT_FOUND, description=No document to update: projects/*/123, cause=null}

Viewed 16

I don't know why it's giving this error and also not updating the data in firestore.

                                          FirebaseFirestore.instance
                                          .collection('extra')
                                          .doc(widget.extraName)
                                          .update(
                                        {
                                          'subExtra':
                                              FieldValue.arrayUnion([
                                            {
                                              'name':
                                                  _subNameTextController
                                                      .text,
                                            }
                                          ])
                                        },
                                      );
1 Answers

In order to call update on a document, that document has to exist already. The error message indicates that no document with the widget.extraName name was found in the extra collection.


If the document indeed isn't supposed to exist yet, you call set (instead of update) to create it with the data you specify.

FirebaseFirestore.instance
  .collection('extra')
  .doc(widget.extraName)
  .set({ ... }); // 

If the document may or may not exist yet, you can call set with merge options specifying that you want to merge the data into the existing document if that already exists, or create the document with the specified data otherwise. So:

FirebaseFirestore.instance
  .collection('extra')
  .doc(widget.extraName)
  .set({ ... }, SetOptions(merge: true)); // 
Related