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

标签 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

最佳答案

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

相关文章:

facebook - Firebase Facebook 身份验证 - 重新请求权限

javascript - Chrome 使用 AudioContext 时更改音频元素源的问题

javascript - 一起显示英里每小时和公里每小时?

javascript - 对同一页面上的多个 html 表单重用 JavaScript 脚本

node.js - 类型错误 : fsevents is not a constructor (already tried a bunch of answers)

node.js - Cloudfoundry 上的非 http TCP 连接

node.js - 带有 Nest js 后端 api 的 Azure Active Directory Spa 用户流程

android - 在android中使用进度条将大小<250KB的文件上传到Firebase

angularjs - Thinkster.io Angular 第 6 章错误 - auth.logout() 不起作用

javascript - 电子、 react 、Webpack "Uncaught SyntaxError: Unexpected reserved word"