kt1*_*t14 2 node.js firebase google-cloud-firestore
我正在使用set功能在Firestore中创建一个新文档。我想在set函数将数据推入数据库后使用文档数据。
// Add each record to their respective heads
let docRef = headCollectionRef.doc(data.headSlug).collection(recordsCollection)
.doc(String(data.recordData.sNo))
docRef.set(data).then(docSnap => {
agreementData.push(
docSnap.get().then(data => {
return data
})
)
})
Run Code Online (Sandbox Code Playgroud)
中没有任何then()内容被执行。
任何帮助深表感谢
set返回Promise<void>,因此您无权访问其中的doc数据then。
在这种情况下,异步/等待将使您的代码更易于阅读。
async function cool() {
const docRef = headCollectionRef.doc(...)
await docRef.set(data)
const docSnap = await docRef.get()
agreementData.push( docSnap.data() )
}
Run Code Online (Sandbox Code Playgroud)
https://firebase.google.com/docs/reference/js/firebase.firestore.DocumentReference#set
| 归档时间: |
|
| 查看次数: |
846 次 |
| 最近记录: |