我目前在反應應用程序的前端初始化了 firebase。在應用程序中,我使用以下代碼更新用戶文檔: const handleProfileUpdate = async () => { const sourceRef = firestore() .collection('users') .where('userId', '==', state.currentUser.userId) sourceRef .get() .then(async snapshot => { if (snapshot.empty) { console.log('user not found') } else { snapshot.forEach(async doc => { await doc.ref.update({ firstName: detailsToUpdate }) console.log(doc) }) } }) .catch(error => console.log(error.code)) }文檔已成功更新,但我想返回對更新文檔的引用,而不是必須再次查詢用戶文檔。.update() 是否返回對更新文檔的引用,或者我應該采取另一種方式來解決這個問題?
在 Firestore 中更新后返回新更新的文檔
四季花海
2023-06-15 15:59:15