在我的代码中的Cloud Firestore中创建新集合 [英] Creating new collection in cloud firestore inside my code

查看:35
本文介绍了在我的代码中的Cloud Firestore中创建新集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我只是想知道是否有任何方法可以将新的子集合自动放入Firestore中?

So I was just wondering if there is any way to automatically put a new sub collection in the firestore?

基本上我的数据结构是主集合比赛",然后我想创建带有季节名称的子集合,例如"s2018","s2019"等...

Basically my data structure is the main collection 'matches' and then I wanted to create subcollections with names of the seasons such as 's2018', 's2019' etc...

因此,不必将其全部手动放置在控制台中.我想创建一个按钮以在网站上添加新的季节.我知道在集合中创建一个新文档很容易,但是我可以在我的React应用程序中使用诸如addCollection()之类的任何方式或代码吗?

So instead of putting it all manually in the console. I wanted to create a button to add a new season on the website. I know it's easy to create a new document inside the collection but is there any way or code like addCollection() that I can use in my react application?

这是我的数据的结构方式:

Here is how my data is structured:

比赛(主集合)->季节(几个子集合)->比赛(带有比赛和球队结果的文件)

Matches(main collection) -> seasons(several sub collections) -> match(document with the result of the match and teams)

我正在寻找

db.collection.addCollection() 

或这种特殊类型的东西在填写详细信息并按下提交按钮后创建一个新集合.

or something in this particular type to create a new collection after filling up details and pressing the submit button.

推荐答案

当您第一次向其中写入文档时,会自动创建一个集合.无需分开预先创建它们.

A collection is automatically created when you first write a document to it. There is no need to separate pre-create them.

另请参阅:

这篇关于在我的代码中的Cloud Firestore中创建新集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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