[英]Firestore - How to get document id after adding a document to a collection
[英]Firebase FireStore : How to get document snapshot after adding document with addDoc()
所以在firebase 8中,可以做到
const songRef = await songCollection.add(song);
然后
const screenShot = await songRef.get()
但是 firebase 9 使用 addDoc() 方法创建文档,所以我可以添加文档
const songRef = await addDoc(songsCollection, song);
但是得到的songRef.get()不是function。那么如何得到刚刚创建的文档快照呢?
songRef
应包含一个id
,您可以使用它来获取文档,如下所示: getDoc(songRef.id)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.