【问题标题】:Get Firestore generated doc ID after set设置后获取 Firestore 生成的文档 ID
【发布时间】:2018-03-07 07:26:08
【问题描述】:

将文档保存到 Firestore 后,有没有办法获取生成的文档 ID?

var collection = db.collection("Users").doc();
collection.set({
                  xxx:"stuff",
                  yyy:"stuff"
               })
                .then(function (?Something?) 
                  {
                    var theIdIWant = ?Something?;
                  }
               )

编辑:或者只是

var myID = collection.id

【问题讨论】:

    标签: firebase google-cloud-firestore


    【解决方案1】:

    doc() 的返回值是 DocumentReference,在其 id 字段中具有唯一 ID。

    var doc = db.collection("Users").doc();
    doc.set({
        xxx:"stuff",
        yyy:"stuff"
    })
    .then(() => { 
        var theIdIWant = doc.id
    })
    

    【讨论】:

      猜你喜欢
      • 2019-11-15
      • 2018-09-03
      • 1970-01-01
      • 1970-01-01
      • 2020-12-04
      • 2021-07-20
      • 1970-01-01
      • 2021-03-29
      • 2019-07-04
      相关资源
      最近更新 更多