递增编号作为Firestore文档名称? [英] Incrementing Number as Firestore Document Name?

查看:58
本文介绍了递增编号作为Firestore文档名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上希望在标题中进行总结,以便使在特定集合中创建的每个新文档都具有递增的序列号.这是为了正确跟踪写入数据库的新订单. AutoID是随机的,会导致排序问题,我希望数据易于管理.是否可以通过Cloud Functions实现?我可以看一下示例代码片段吗?谢谢!

Basically summed up in the title, I would like to make it so that each new document being created in a particular collection has an increment sort of serial number to it. This is for properly tracking the new orders that are written to the database. AutoID is random and causes sorting issues, I would like the data to be easily manageable. Is this possible to achieve via Cloud Functions? Any sample code snippets I can look at? Thank you!

推荐答案

根据@Frank van Puffelen的评论,为此使用顺序ID是一种反模式".您的用例在Firestore文档中也提到了此处:

As per @Frank van Puffelen comment, "Using sequential IDs for that is an anti-pattern". Your use case is also mentioned in the Firestore documentation here:

重要提示:与Firebase实时数据库中的推送ID"不同,Cloud Firestore自动生成的ID不提供任何自动排序.如果 您希望能够按创建日期订购文档, 应该将时间戳记存储为文档中的字段.

Important: Unlike "push IDs" in the Firebase Realtime Database, Cloud Firestore auto-generated IDs do not provide any automatic ordering. If you want to be able to order your documents by creation date, you should store a timestamp as a field in the documents.

这篇关于递增编号作为Firestore文档名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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