I am currently trying to structure and organize my Firestore Database in my app. Essentially, the first collection of my app will contain my "users" with documents labeled with the email of every user who signs up. I was successfully able to label each document in my "users" database by referencing the Authentication module of Firebase but cannot seem to append data under the individual document paths. I don't know if this is bad practice or not, but this application is for demonstration purposes.
This works successfully in creating an email references in the docs
let db = Firestore.firestore()
db.collection("users").document("\(userEmail)").setData(["firstname":firstname, "lastname":lastname, "uid": result!.user.uid,"email address": email ]) { (error) in
if error != nil {
self.showError("Email has already been used")
This is where I have a problem and the all of the new information is being stored under the a FIRDocumentReference
let iceName1 = iceName1TextField.text!
let iceNumber1 = iceNumber1TextField.text!
let iceName2 = iceName2TextField.text!
let iceNumber2 = iceNumber2TextField.text!
let currentUserEmail = Auth.auth().currentUser!.email
//using this, we can recieve the users email. I don't really know how else to recieve user email so we will need to have someone do that.
let docData: [String : Any] = ["ICE-Name-1" : iceName1 , "ICE-Number-1" : iceNumber1 , "ICE-Name-2" : iceName2, "ICE-Number-2" : iceNumber2]
let userEmail = db.collection("users").document("\(String(describing: currentUserEmail))")
// apparently the document that I am describing above may not exist, therefore, swift is creating document references that are no existent. We need to fix this.
//store data into firebase
let db = Firestore.firestore()
db.collection("users").document("\(userEmail)").setData(docData)
//this appends following information to firebase database
saveLabel.alpha = 1