【问题标题】:How to write data to a subcollection of Firestore in v9 react JS如何在 v9 react JS 中将数据写入 Firestore 的子集合
【发布时间】:2021-11-04 00:13:11
【问题描述】:
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中应该如何?

【问题讨论】:

  • 我认为最好的检查方法是官方文档。他们甚至提供了如何将 V8 代码转换为 v9 代码

标签: javascript reactjs firebase


【解决方案1】:
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 });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-15
    • 1970-01-01
    • 1970-01-01
    • 2021-12-09
    • 2022-12-06
    相关资源
    最近更新 更多