亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Firestore:寫一個新文檔,然后立即返回新文檔?

Firestore:寫一個新文檔,然后立即返回新文檔?

烙印99 2023-05-19 16:18:21
有沒有辦法一次性寫入 -> 讀取 firestore 中新添加的文檔?我一直在寫,然后進行第二個查詢來閱讀它,雖然它有效,但我想知道是否有替代我下面的內容。const someAsyncFunc = async () => {? try {? ? ? const lesson = await userLessonRef.get();? ? ? if (lesson.exists) {? ? ? ? // ? if lesson exists, return it.? ? ? ? return lesson.data();? ? ? }? ? ? // ? if lesson does NOT exist, create it.? ? ? await firebaseFirestore? ? ? ? .collection(`users/${userID}/languages/${language}/lessons`)? ? ? ? .doc(lessonID)? ? ? ? .set({ greetings: 'hello' });? ? ? // ? return the newly created lesson.? ? ? const newLesson = await firebaseFirestore? ? ? ? .collection(`users/${userID}/languages/${language}/lessons`)? ? ? ? .doc(lessonID)? ? ? ? .get();? ? ? return newLesson.data();? } catch (error) {? ? console.log('Error finding lesson collection', error);? }}
查看完整描述

1 回答

?
小怪獸愛吃肉

TA貢獻1852條經驗 獲得超1個贊

除了事務(這是先讀后寫的組合操作,沒有組合的寫/讀操作。如果在寫入文檔后需要文檔的全部內容,則必須執行讀取。



查看完整回答
反對 回復 2023-05-19
  • 1 回答
  • 0 關注
  • 229 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號