簡體   English   中英

如何在v9 react JS中將數據寫入Firestore的子集合

[英]How to write data to a subcollection of Firestore in v9 react JS

db.collection("rooms").doc(channelId).collection("messages").add({
  message: input,
  timestamp: serverTimestamp(),
  user: 'Apollos',
  userImage: 'https://naniwallpaper.com/files/wallpapers/eren-yeager/1-EREN%20YEAGER-1080x1920.jpg'
});

這應該如何在 firestore v9 中出現?

import { doc } from "firebase/firestore"; 

const messageRef = doc(db, "rooms", chanelID, "messages");

const update = {
  message: input,
  timestamp: serverTimestamp(),
  user: 'Apollos',
  userImage: 'https://naniwallpaper.com/files/wallpapers/eren-yeager/1-EREN%20YEAGER-1080x1920.jpg'
}

 setDoc(messageRef, update, { merge: true });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM