简体   繁体   中英

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'
});

How should this be in 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 });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM