如何将子集合添加到firestore中的文档?

时间:2018-02-19 20:10:27

标签: javascript node.js firebase vue.js google-cloud-firestore

没有关于如何在firestore中的文档中添加子集合的文档, 如何使用Web应用程序添加子集合? even tried like this but didn't worked。 如何使用代码在应用程序中添加子集合? 有没有办法做到这一点,或者使用firebase实时数据库会更好? 如果是这样,请告诉我如何在firebase中进行操作i want to add like this i did this但是我收到了这样的错误the error says this

1 个答案:

答案 0 :(得分:12)

如果您将.set更改为.add,则您的代码应该有效。然后,Cloud Firestore将为该文档发布新ID。如果您想指定文档ID,那么您需要执行此操作...

设置具有给定ID

的图书
db.collection('users').doc(this.username).collection('booksList').doc(myBookId).set({
  password: this.password,
  name: this.name,
  rollno: this.rollno
})

此页面详细介绍了如何Add data to Cloud Firestore

添加一本书

db.collection('users').doc(this.username).collection('booksList').add({
  password: this.password,
  name: this.name,
  rollno: this.rollno
})
相关问题