如何将子集合添加到Firestore中的文档? [英] how to add sub collection to a document in firestore?

查看:81
本文介绍了如何将子集合添加到Firestore中的文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

没有关于如何在Firestore中的文档中添加子集合的文档, 如何通过使用Web应用程序添加子集合? 甚至尝试过这种方法但没有成功. 如何使用代码在应用程序中添加子集合? 有什么办法可以做到,还是使用Firebase实时数据库会更好? 如果是这样,请也让我知道如何在Firebase中执行此操作我要添加这样的内容 我做到了,但我却收到了这样的错误

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 this i did this but iam getting an error like this the error says this

推荐答案

如果将.set更改为.add,则您的代码应该可以工作.然后,Cloud Firestore将为该文档发出新的ID.如果要指定文档ID,则需要执行此操作...

Your code should work if you change .set to .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...

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

此页面详细说明了如何将数据添加到Cloud Firestore

This page details how to Add data to Cloud Firestore

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

这篇关于如何将子集合添加到Firestore中的文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆