0

My app allows users to make a post. From this post, any user can make a request. I want to make a function where the owner of the post can update a field in all the requests made to his/her post, Let's say 'canceled' or 'delete' for example.

The picture below might help explain what I meant

diagram for updating

The user 'A' accesses his/her posts Main collection. Then there is a button that says CANCEL. On the click of this button firebase should check if there is a request sent to this post in the Sub-collection. If there is a request, then a field, say 'Post-Status', in all the requests made to this post should be updated.

I know this code is wrong but this is the best I could come up with.

// inside the TextButton

FirebaseFirestore.instance.collection('main-collection name').doc(current-user-id).collection('sub-collection name').doc("I don't know what to put here").set({"Post-Status": "Canceled"}).

N/B: when I tried the code below, without putting anyting in the doc() for the subcollection, it creates a whole new collection in the sub-collection

FirebaseFirestore.instance.collection('main-collection name').doc(current-user-id).collection('sub-collection name').doc().set({"Post-Status": "Canceled"}).
Eben Oasis
  • 69
  • 6
  • https://stackoverflow.com/questions/48947499/can-firestore-update-multiple-documents-matching-a-condition-using-one-query – Shri Hari L Apr 17 '23 at 11:42

0 Answers0