【问题标题】:Generate unique ID like Firebase Firestore [duplicate]生成像 Firebase Firestore 这样的唯一 ID [重复]
【发布时间】:2018-11-14 13:27:21
【问题描述】:

我想在 Firestore 中创建一个具有唯一 ID 和唯一 ID 后面的名称的文档。为此,我想创建相同类型的 firebase firestore 唯一 ID。

  • 如何使用自动生成的 Firestore ID 创建唯一 ID?
  • Firebase Admin SDK 中是否有功能?

更新:

正如 Frank van Puffelen 在 cmets 中提到的,AutoId 是我的正确选择!

这是我在服务器端与 node.js 一起使用的函数:

function generateUniqueFirestoreId(){
  // Alphanumeric characters
  const chars =
    'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  let autoId = '';
  for (let i = 0; i < 20; i++) {
    autoId += chars.charAt(Math.floor(Math.random() * chars.length));
  }

  return autoId;
}

【问题讨论】:

标签: node.js firebase google-cloud-firestore


【解决方案1】:

您可以使用 uuid 包。

【讨论】:

  • 我知道 uuid 包,但我需要一个具有 firestore 自动生成的 id 类型的 id。谢谢
  • 您能否更具体地了解“firestore 自动生成的 id”是什么意思?
  • p8s3R6LZrE43MbJWyyKb
猜你喜欢
  • 2012-05-02
  • 1970-01-01
  • 1970-01-01
  • 2012-08-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-21
  • 1970-01-01
相关资源
最近更新 更多