Firebase onCreate函数只返回众多创作中的一个

时间:2018-02-15 15:46:53

标签: javascript firebase firebase-realtime-database google-cloud-functions

我有这段代码:

exports.elevation = functions.database.ref('/ships_for_locations').onCreate(event => {

    const original = event.data.val();
    console.log(JSON.stringify(original) + "      event.data.val() ---------------");

    ...

Firebase功能日志中original的控制台输出为:

  

{ “5eb0fbc824d2d48ce9e5cbc76a7a2e643b016009”:{ “ship15”:{ “克”: “drt2k6vxuuwy”, “L”:[42.247907072461054,-71.17265374654367]}, “ship8”:{ “升”:[42.24786474369262,-71.1727565570968] “G”: “drt2k6vxdsf1”}, “ship3”:{ “克”: “drt2k6vxg21n”, “L”:[42.247882900393094,-71.17272600000001]}, “ship11”:{ “升”:[42.24787704060876,-71.17272600000001] “G”: “drt2k6vxer15”}, “ship4”:{ “升”:[42.247838578422375,-71.17272600000001], “G”: “drt2k6vx7rcj”}, “ship16”:{ “升”:[42.24785870234929,-71.17277992860309] “G”: “drt2k6vxd58v”}, “SHIP1”:{ “升”:[42.247865,-71.17270322375195], “G”: “drt2k6vxeucg”}, “ship7”:{ “升”:[42.24787169684869,-71.17270156462881] “G”: “drt2k6vxey55”}, “ship13”:{ “升”:[42.247842662420545,-71.17268807527044], “G”: “drt2k6vxs0tq”}, “SHIP2”:{ “克”: “drt2k6vxdsge”, “升” :42.247865,-71.17275457694687]} “配送6”:{ “升”:[42.247873403962814,-71.17273898101789], “G”: “drt2k6vxdyrm”}, “ship12”:{ “克”: “drt2k6vx7m3h”, “升” :[42.247825005009005,-71.17272600000001]}, “ship14”:{ “升”:[42.247875702512644,-71.17276722073039], “G”: “drt2k6vxdqf7”}, “ship9”:{ “L”:[42.247 865,-71.17272043195321], “G”: “drt2k6vxekv5”}, “ship5”:{ “克”: “drt2k6vxkpbw”, “L”:[42.247838767805725,-71.17269442665282]}, “ship10”:{ “L”:[ 42.247865,-71.17276938808422], “G”: “drt2k6vxdkbe”}}}   event.data.val()---------------

但是(与上面的数据不匹配),我使用我的脚本向数据库引用添加了多个项目。

以下是我的数据库在我的脚本运行后ships_for_locations引用的数据库的标签 - https://pastebin.com/Us4we4MU

您可以看到有多个条目。但是,当我的onCreate函数运行时,它只返回一个条目(正如我在开头所示)。我是否超过了配额或什么? (我调查了一下,找不到任何东西)。我需要/ships_for_locations的所有条目,所以我可以遍历它们。感谢

2 个答案:

答案 0 :(得分:0)

从您所引用的0abf655263c3c9fed49387125c265120a4090be8节点中保存一个对象并创建一次,另一方面,您应该在{{1}下直接拥有不同的船只(ship1,ship2,...)使用自己的ID或ships_for_locations作为ID

引用

答案 1 :(得分:0)

我将对ElementRef的引用更改为ParentComponent - 并相应地更改了我的代码。