Javascript 如何将子集合添加到firestore中的文档?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48873465/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to add sub collection to a document in firestore?
提问by user8167002
there is no documentation about how add sub collection in a document in firestore, how to add a sub collection by using a web app? even tried like this but didn't worked. how can i add a sub collection in apps by using code? is there any way to do it or it will be better to use firebase real time database? if it so, please let me know how to do it in firebase as welli want to add like thisi did thisbut iam getting an error like this the error says this
没有关于如何在 firestore 的文档中添加子集合的文档,如何使用 Web 应用程序添加子集合? 甚至像这样尝试但没有奏效。如何使用代码在应用程序中添加子集合?有没有办法做到这一点,或者使用firebase实时数据库会更好?如果是这样,请让我知道如何在 firebase 中执行此操作我想像这样添加我这样做了但我收到这样的错误错误说明
回答by Jason Berryman
Your code should work if you change .setto .add. Cloud Firestore will then issue a new ID for that document. If you want to specify the document ID, then you'll need to do this...
如果您更改.set为.add. 然后,Cloud Firestore 将为该文档发布一个新 ID。如果要指定文档 ID,则需要执行此操作...
Set a book with a given ID
设置具有给定 ID 的图书
db.collection('users').doc(this.username).collection('booksList').doc(myBookId).set({
password: this.password,
name: this.name,
rollno: this.rollno
})
This page details how to Add data to Cloud Firestore
此页面详细介绍了如何将数据添加到 Cloud Firestore
Add a book
添加一本书
db.collection('users').doc(this.username).collection('booksList').add({
password: this.password,
name: this.name,
rollno: this.rollno
})

