when trying to add an element to an existing array in firestore I get the error "Cannot convert value of type 'String' to expected argument type '[Any]'"
this is the method where the error occurs:
func addEventIdToUser(eventID: String) async {
let db = Firestore.firestore()
let userReference = try await db.collection("user").document(userID)
try? await userReference.updateData(["events": FieldValue.arrayUnion(eventID)])
}
does anyone know how to solve the issue?
SOLUTION:
I forgot brackets around eventID
this is the right way:
try? await userReference.updateData(["events": FieldValue.arrayUnion([eventID])])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.