如何在Google Cloud Firestore中获得插入的文档ID

时间:2019-08-20 02:38:43

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

在Google Cloud Firebase中插入新文档后,是否可以返回文档ID?

这是到目前为止我的保存方法的一个示例:

save(entity:any){
    entity = JSON.parse(JSON.stringify(entity)); 

    if(entity.id){
        return db.collection(this.collectionName).doc(entity.id).update(entity);
    }else{
        // How to return the newly created document id from here?
        return db.collection(this.collectionName).doc().set(entity);
    }
}

编辑:这是我要引用的有价文件ID的突出显示示例

enter image description here

0 个答案:

没有答案