【发布时间】:2020-08-17 04:51:26
【问题描述】:
db.collection("rooms").add({
code: this.state.code,
words: []
}).then(() => {
db.collection("rooms").where("code", "==", this.state.code).get().then((doc) => {
doc.collection("players").add({name: this.state.name, votes: 0}).then(() => {
socket.emit("createGroup", this.state.code);
});
});
});
我正在使用客户端 Firestore 调用和 SocketIO 构建一个 React/Express 应用程序。我在控制台中收到以下错误:“Uncaught (in promise) TypeError: t.collection is not a function”。我猜当我在 then 函数中引用 Firestore 文档 -> {code: this.state.code, words: []} 时,不知何故尚未创建它 -> db.collection("rooms").where("code", "==", this.state.code)。关于如何在保持 Firestore 调用顺序的同时修复此错误的任何建议?
【问题讨论】:
标签: javascript firebase google-cloud-firestore