在ReactJs中设置后获取Firestore生成的文档ID

时间:2018-03-07 07:26:09

标签: reactjs firebase google-cloud-firestore

在您将文档保存到firestore之后,有没有办法获取生成的文档ID?

antiJARLocking

enter image description here

编辑:或者只是

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

1 个答案:

答案 0 :(得分:7)

doc()的返回值为DocumentReference,其id字段中包含唯一ID。

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