[英]How can I create Subcollection in document?
I want to create under every Restaurant document empty Subcollection where I will be adding new reservations.我想在每个 Restaurant 文档下创建一个空的子集合,我将在其中添加新的预订。 All Restaurant documents are in Restaurants collection.所有 Restaurant 文档都在 Restaurants 集合中。
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.在 firebase 中,除非您向其中写入内容,否则不会创建该集合。 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:)快乐编码:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.