node.js - Firebase云功能同步nodejs

标签 node.js firebase-realtime-database google-cloud-functions

为什么我的 Firebase 控制台总是出现“Promise {待处理}”?

enter image description here 我很确定我正确地使用了带有“.then”的 promise 概念。我的函数出了什么问题? (与亚历山大主教编辑)

exports.GenerateLiveGameIfAllPlayerReady = functions.database.ref("games/lobby/{pushId}/playerList/{playerId}").onUpdate(event => {
//Get the object of the game then put it in the Live games node
const transfertNewLiveGame = event.data.ref.parent.parent.once('value').then(snap => {
    return snap.val();
}).then(() => {
    console.log(transfertNewLiveGame);
    console.log(event.params.pushId);

    return admin.database().ref('games/live').update({
        [event.params.pushId]: transfertNewLiveGame
    });
})

最佳答案

正如您所说,触发函数需要Promise,但您缺少return。所以你的代码应该是这样的。

exports.GenerateLiveGameIfAllPlayerReady = functions.database.ref("games/lobby/{pushId}/playerList/{playerId}").onUpdate(event => {

      return event.data.ref.parent.parent.once('value', function(snap) {

            return admin.database().ref('games/live').update({
                [event.params.pushId]: snap.val()
            });

      });

关于node.js - Firebase云功能同步nodejs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49099055/

相关文章:

node.js - 如何更改socket.io 获取socket.io.js JavaScript 文件的文件夹?

android - 如何使用 FirebaseRecyclerViewAdapter 在扁平结构 Firebase 中导航

java.lang.RuntimeException : Could not deserialize object. 无法将 java.lang.Long 类型的值转换为 boolean 值

javascript - 动态更改的 Firebase URL

node.js - 如何快速搭建大规模分析服务器?

node.js - ReactJS 从 Express 服务器下载文件

go - 使用 Golang 的 Google Cloud Functions 工作流

node.js - 将 Firestore 依赖项和类型导入到 node.js

javascript - "documentRef"不是更新字段时显示的有效 DocumentReference

node.js - 错误: Incompatible SOCKS protocol version: 71