简体   繁体   English

如何在文档中创建子集合?

[英]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.

相关问题 我如何根据其子集合 firestore 中的内容获取文档? - how do i get a document based on whats in its subcollection firestore? 如何删除子集合中的文档 - How to delete a document inside a subcollection 如何在快照侦听器中获取子集合的父文档? - How to get parent document of subcollection in a snapshot listener? 如何从子集合中获取特定文档 - How to fetch a specific document from inside the subcollection Android Firebase,如何检查文档中是否存在子集合 - Android Firebase, How to check if a subcollection exists within a document 如何从所有文档的子集合中检索所有数据 - How to retrieve all data from a subcollection of all document 如何在 firestore 中获取子集合路径 - how do I get subcollection path in firestore 如何在使用 flutter 在 Firestore 中创建的用户文档中添加子集合 - How to add a subcollection in a users document that has been created in Firestore with flutter 如何定义只有登录用户才能读取和写入所有 collections 和子集合的安全规则? - How do I define the security rules where only logged in user can read and write all of the collections and subcollection? 如何将子集合添加到 firestore 中的子集合,反应应用程序 - How to add subcollection to a subcollection in firestore, react app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM