2017-10-15 24 views
1

新しく作成されたドキュメントの新しい属性を、onCreate()クラウドファイアストアトリガーによってトリガーされたクラウド関数で追加する方法。 クライアント側だけでなくサーバー側、つまりクラウド機能で文書を更新するのに同じアプローチを使用できますか? the docsパーGoogle Cloud Firestoreトリガー

答えて

2

、あなたが操作を実行するためにevent.data.refを使用することができます。

exports.addUserProperty = functions.firestore 
    .document('users/{userId}') 
    .onCreate(event => { 
    // Get an object representing the document 
    // e.g. {'name': 'Marie', 'age': 66} 
    var data = event.data.data(); 

    // add a new property to the user object, write it to Firestore 
    return event.data.ref.update({ 
     "born": "Poland" 
    }); 
}); 
+0

私は、ドキュメントID –

+0

を知らないので、私は、特定のドキュメントのパスを追加する方法documents.Thenのための自動生成されたIDの選びましたこれは、ワイルドカード '{wildcardId}'のためのものです。その場所のすべての変更を取得します。 –

関連する問題