Firebase在不知道密钥的情况下从子列表中检索数据(Web)

时间:2017-02-14 21:23:10

标签: javascript firebase server firebase-realtime-database

我正在开发一个允许某些用户发送其他推送通知的Web应用程序。用户列表"已订阅"任何一个用户都存储在firebase数据库中,结构如下;

senderUserID
    senderSubscribers
        subscriberOneID
            token: subToken
        subscriberTwoID
            token: subToken
        subscriberThreeID
            token: subToken

基本上我需要将令牌列表存储在一个数组中,以便使用它们中的每一个来指定接收推送通知的客户端。

这是我的javaScript,它返回订阅者列表' Node'。就我而言,senderSubscribers实际上就是“玩家”。

firebase.database().ref('/users/'+currentUserId+'/players/').once('value').then(function(snapshot){
        var allPlayersNode = snapshot.val();
        console.log(allPlayersNode);
});

Console.log看起来像

firstUserID:Object
    regID: the first subscribers token
secondUserID:Object
    regID: the second subscribers token

JSON代码:

 "emails" : {
    "kylebehiels@hotmail" : "vlHVHcIetlZp7zS8mm6GcwoFRsB3",
    "test@gmail" : "hJuVfpGTJvRyP4qsA6xyyvgQDay1"
  },
  "users" : {
    "hJuVfpGTJvRyP4qsA6xyyvgQDay1" : {
      "email" : "test@gmail.com",
      "first_name" : "kyle",
      "games" : {
        "placeholder" : "placeholder"
      },
      "last_name" : "behiels",
      "practices" : {
        "placeholder" : "placeholder"
      },
      "regid" : "c_z_KWeWorU:APA91bHORVZqSph-HikfxtO2XjvMnwudIymORoSm9t3gupKZ1fFIZCLxGUbX5dsrYooHHpeEiPXhcXEMu5Eo5-nwF8bBjw-OTwSbn_rujTuPVaCDOXUKp9mzIYqeZq7SFMaWssZfyKj7",
      "workouts" : {
        "placeholder" : "placeholder"
      }
    },
    "vlHVHcIetlZp7zS8mm6GcwoFRsB3" : {
      "email" : "kylebehiels@hotmail.com",
      "first_name" : "kyle",
      "games" : {
        "placeholder" : "placeholder"
      },
      "last_name" : "behiels",
      "players" : {
        "hJuVfpGTJvRyP4qsA6xyyvgQDay1" : {
          "playerRegID" : "c_z_KWeWorU:APA91bHORVZqSph-HikfxtO2XjvMnwudIymORoSm9t3gupKZ1fFIZCLxGUbX5dsrYooHHpeEiPXhcXEMu5Eo5-nwF8bBjw-OTwSbn_rujTuPVaCDOXUKp9mzIYqeZq7SFMaWssZfyKj7"
        },
        "vlHVHcIetlZp7zS8mm6GcwoFRsB3" : {
          "playerRegID" : "cvZj3hb_zkk:APA91bEcmKlDlC5VKOI6wc1BvRI5mGgmWFA3QuTR3jH48l9fz565RhY2PEXE2GkXyhKXgb67qu7ieRlWF403q6rQPi0-xgGIbfvOkhGzopfyTFLNQg7ADgNHFAd1YfwwesbHjL5IHLZd"
        }
      },
      "practices" : {
        "placeholder" : "placeholder"
      },
      "regid" : "cvZj3hb_zkk:APA91bEcmKlDlC5VKOI6wc1BvRI5mGgmWFA3QuTR3jH48l9fz565RhY2PEXE2GkXyhKXgb67qu7ieRlWF403q6rQPi0-xgGIbfvOkhGzopfyTFLNQg7ADgNHFAd1YfwwesbHjL5IHLZd",
      "workouts" : {
        "placeholder" : "placeholder"
      }
    }
  }
}

0 个答案:

没有答案