问题描述
我正在尝试根据日期创建一个集合名称,例如我具有这样的集合名称(更改为06-05-2020),并且我想每天覆盖此集合,并将集合名称设置为此类(更改时间为07-05-2020)依此类推,是否有可能以这种方式创建馆藏?基本上,我正在尝试以特定方式存储每日更新的数据,以便我可以跟踪该信息.所以我可以每天动态更新馆藏名称吗?
I am trying to create a collection name based on the date like i have a collection name like this Change 06-05-2020 and i want to overwrite this collection daily and make the collection name like this Change 07-05-2020 and so on is it possible to do it i ma creating the collection in this way.and basically i am trying to store the daily updated data in a particular way so i can track that information.so can i update the collection name dynamically daily?
await growthfilemsdb.collection(`Change${getISO8601Date()}`).doc(change.after.data().officeId).set(change.after.data(),{merge:false})
推荐答案
无法更改集合的名称.您可以做的就是简单地将所有文档从旧集合复制到新名称的新文档中.
It's not possible to change the name of a collection. What you can do instead is simply copy all the documents from the old collection to a new one with a new name.
但是,通常不希望这样使集合的名称具有动态性.相反,可以考虑将日期作为文档中的一个字段,然后使用它来过滤查询结果或删除旧文档.
However, it's usually not a good idea to make the names of your collection dynamic like this. Instead, consider putting the date as a field inside the document, and using that to filter the results of queries or delete old documents.
这篇关于可以在Cloud Firestore中动态更新集合名称吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!