Firestore 和自动增量 ID

编程入门 行业动态 更新时间:2024-10-25 12:28:17
本文介绍了Firestore 和自动增量 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我目前正在将 firestore 用于一个小型应用程序.我想看看我可以用什么来自动增加 id.一个常见的简单用例是订单号.我不想使用文档 ID 的人类消耗品标识符.这对人类来说是不可消耗的.

I am currently using firestore for a small application. I am trying to see what I can use for auto increment ids. A simple use case which is common is order nos. A human consumable identifier I dont want to use the document id. This is not consumable for humans.

推荐答案

Firestore 中没有内置的自增运算符.如果你想要这样的东西,你将不得不自己构建它.

There is no built-in auto-increment operator in Firestore. If you want something like that, you will have to build it yourself.

这通常涉及跟踪您在已知位置的文档中使用的最新 ID,然后在事务中从客户端读取和更新该文档.

This typically involves keeping track of the latest ID you've used in a document in a well-known location, and then reading-and-updating that document from the client in a transaction.

但是请认真考虑是否不能使用 Firestore 的内置标识符,因为 Firestore 带有内置标识符而不是自动递增运算符的原因有很多.

But do seriously consider whether you can't use Firestore's built-in identifiers, as there are many reasons why Firestore comes with those built-in instead of having an auto-increment operator.

我强烈建议您查看其中一些相关问题:

I highly recommend checking out some of these related questions:

  • 将数字递增为 Firestore 文档名称?
  • Firestore 生成的键与集合中的自定义键?
  • 如何在 Firebase 中创建自增键?(关于 Firebase 的其他数据库,但原因大致相同)
  • Incrementing Number as Firestore Document Name?
  • Firestore generated key versus custom key in a collection?
  • How to create auto incremented key in Firebase? (about Firebase's other database, but the reasons are largely the same)

以及分布式计数器中的 Firestore 文档中的此页面.

更多推荐

Firestore 和自动增量 ID

本文发布于:2023-10-15 02:34:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492998.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:增量   Firestore   ID

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!