[英]Cloud Firestore: Add collection and sub collection in one go
Reading the documentation I can't see a way if this is possible in a sensible way. 在阅读文档时,我无法找到一种可行的方法。
I'm trying to create a document team
with a sub document of member
. 我正在尝试创建一个由
member
的子文档member
的文档team
。
And what I'm really trying to achieve is an in-complex way of structuring read/writes/updates on collections and sub collections. 我真正想要实现的是一种复杂的方式来构造对集合和子集合的读/写/更新。
async createTeam(newTeam, foundingTeamMember) {
const teams = db.collection('teams');
const teamRef = await db.collection('teams').add(newTeam);
const memberRef = await teams.doc(companyRef.id)
.collection('members').add(foundingTeamMember);
return({
teamId: teamRef.id,
memberId: memberRef.id,
});
}
In particular is there a means of returning teamId
and memberId
without needing to use async / await? 特别是有一种无需使用async / await就可以返回
teamId
和memberId
吗?
Something like: 就像是:
db
.collection('teams')
.add(newTeam)
.collection('members')
.add(foundingTeamMember).then(/* return collection parent ID */)
The random IDs for new documents are always generated on the client. 新文档的随机ID始终在客户端上生成。 You can use the doc() method on a CollectionReference with no parameters to generate a reference to a document that has a random ID without actually adding the document.
您可以在没有参数的CollectionReference上使用doc()方法来生成对具有随机ID的文档的引用,而无需实际添加该文档。 You can then work with that reference's id property immeidately, and create the document later.
然后,您可以立即使用该引用的id属性 ,并在以后创建文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.