回答編集履歴

2

回答追記します。

2018/10/19 16:56

投稿

set0gut1
set0gut1

スコア2413

test CHANGED
@@ -1,3 +1,55 @@
1
1
  内側で id を使うためには context.params.id とする必要があります。
2
2
 
3
3
  参考: [https://firebase.google.com/docs/functions/database-events?hl=ja#handle_event_data](https://firebase.google.com/docs/functions/database-events?hl=ja#handle_event_data)
4
+
5
+
6
+
7
+ -----
8
+
9
+
10
+
11
+ 回答追記します。
12
+
13
+
14
+
15
+ - firebase からのデータの読み込みって promise 使って次のように書いたと思うので試してみてください([https://firebase.google.com/docs/database/web/read-and-write?hl=ja#read_data_once](https://firebase.google.com/docs/database/web/read-and-write?hl=ja#read_data_once))
16
+
17
+ - 非同期関数を呼ぶ際はその promise を返す必要があることに注意です。でないと処理終了を待たずに終わることがあります([https://firebase.google.com/docs/functions/database-events?hl=ja](https://firebase.google.com/docs/functions/database-events?hl=ja))
18
+
19
+
20
+
21
+ ```
22
+
23
+ exports.helloWorld = functions.database
24
+
25
+ .ref('/match/{id}')
26
+
27
+ .onWrite((change, context) => {
28
+
29
+ return functions.database
30
+
31
+ .ref('/Users')
32
+
33
+ .once('value')
34
+
35
+ .then(snapshot => {
36
+
37
+ const item = snapshot.val()
38
+
39
+ console.log('item', item)
40
+
41
+
42
+
43
+ const message = change.after.val()
44
+
45
+ console.log('helloWorld', message)
46
+
47
+
48
+
49
+ return 0
50
+
51
+ })
52
+
53
+ })
54
+
55
+ ```

1

参考url追加

2018/10/19 16:56

投稿

set0gut1
set0gut1

スコア2413

test CHANGED
@@ -1 +1,3 @@
1
- 内側で id を使うためには context.params.id とする必要があります
1
+ 内側で id を使うためには context.params.id とする必要があります
2
+
3
+ 参考: [https://firebase.google.com/docs/functions/database-events?hl=ja#handle_event_data](https://firebase.google.com/docs/functions/database-events?hl=ja#handle_event_data)