gpt4 book ai didi

javascript - 如何将子集合添加到 Firestore 中的文档?

转载 作者:IT老高 更新时间:2023-10-28 23:15:59 24 4
gpt4 key购买 nike

没有关于如何在 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

最佳答案

如果您将 .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
})

关于javascript - 如何将子集合添加到 Firestore 中的文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48873465/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com