I am working a project to use shops. My structure data:
My code snippet
//current user sign in here and uid "VjZfKF1zmrV00C9VeTZxRmogybA2"
let currentUser = Auth.auth().currentUser
let db = Firestore.firestore()
db.collection("Blah").whereField("users", isEqualTo: currentUser?.uid).collection("otherPath").document().addDocument
I want to add data to use currentuser uid and if it is matching "Blah" inside documents then add that targeting document other collection.
.adddocumets
or .setData
it isn't allowed to firestore, so how can i figure it?
CodePudding user response:
There is no way to send a query and an update statement to Firestore in one go. You will instead have to:
- Execute a query to determine all documents that need to be updated.
- Loop over the results of that query in your application code.
- Update each document in turn inside that loop.
In addition, since users
is an array field, you'll want to use the array-contains
operator to match the correct documents.