有沒有辦法一次性寫入 -> 讀取 firestore 中新添加的文檔?我一直在寫,然后進(jìn)行第二個(gè)查詢來閱讀它,雖然它有效,但我想知道是否有替代我下面的內(nèi)容。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);? }}
Firestore:寫一個(gè)新文檔,然后立即返回新文檔?
烙印99
2023-05-19 16:18:21