I want to create under every Restaurant document empty Subcollection where I will be adding new reservations. All Restaurant documents are in Restaurants collection.
let \_ = Firestore.firestore().collection("Restaurants").document(userUID).setData(\[
"userName": userName,
"userEmail": email,
"maxSittingPlaces": sittingplaces,
"description": description,
"openingHours": openingHours,
"adress": adress,
"phoneNumber": phone,
"actualSittingPlaces": sittingplaces,
"imageURL:,": imgURL.self\])
let _ =
--> Firestore.firestore().collection("Restaurants").document(userUID).collection("Reservations")
I don' know how to write command to create Subcollection Reservations in every document Reservation.
In firebase, The collection wont be created unless you write something to it. So remember to write something in the collection you just created.Here's the code for it.
let reservationRef = Firestore.firestore().collection("Restaurants").document(userUID).collection("Reservations")
let reservationData = [ "userName": userName, "userEmail": email]
reservationRef.addDocument(data: reservationData)
Happy Coding:)
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.