質問編集履歴

2

開発環境の内容を追記しました

2018/08/25 08:40

投稿

yamady
yamady

スコア176

test CHANGED
File without changes
test CHANGED
@@ -12,6 +12,18 @@
12
12
 
13
13
 
14
14
 
15
+ 開発環境は
16
+
17
+
18
+
19
+ firebase-functions: ^0.9.1
20
+
21
+
22
+
23
+ です。
24
+
25
+
26
+
15
27
  #### エラー内容
16
28
 
17
29
 

1

ご指摘いただいた箇所を試して見ました

2018/08/25 08:40

投稿

yamady
yamady

スコア176

test CHANGED
File without changes
test CHANGED
@@ -183,3 +183,81 @@
183
183
  timestamp: '2018-08-25T02:30:40.045967Z' }
184
184
 
185
185
  ```
186
+
187
+
188
+
189
+ #### 追記(8月25日)
190
+
191
+
192
+
193
+ ```JavaScript
194
+
195
+ // message push notification
196
+
197
+ exports.messagePush = functions.firestore
198
+
199
+ .document('/rooms/{roomId}/users/{uid}/messages/{messageId}')
200
+
201
+ .onWrite((change, context) => {
202
+
203
+
204
+
205
+ console.log('change', change);
206
+
207
+
208
+
209
+ const document = change.after.exists ? change.after.data() : null;
210
+
211
+
212
+
213
+ console.log('document', document);
214
+
215
+
216
+
217
+ const newDocument = change.after.data();
218
+
219
+ console.log('newDocument', newDocument);
220
+
221
+
222
+
223
+ // Get an object with the previous document value (for update or delete)
224
+
225
+ const oldDocument = change.before.data();
226
+
227
+ console.log('oldDocument', oldDocument);
228
+
229
+
230
+
231
+ ・・・
232
+
233
+ ```
234
+
235
+
236
+
237
+ ご回答をいただきましたようにトライしてみました。
238
+
239
+
240
+
241
+ 上記のように、冒頭を書き加えてみたのですが、下記のエラーが出てしまいました。
242
+
243
+ `console.log('change', change);`は上と同じものを取得できましたは、`exisits`が取得できず止まってしまいました。。
244
+
245
+
246
+
247
+ ```
248
+
249
+ TypeError: Cannot read property 'exists' of undefined
250
+
251
+ ```
252
+
253
+
254
+
255
+ 続いて、existsの構文を消してやってみましたが、やはりデータのところでこけてしまいます。
256
+
257
+
258
+
259
+ ```
260
+
261
+ TypeError: Cannot read property 'data' of undefined
262
+
263
+ ```