小编Nis*_*tel的帖子

如何为 Firestore 数据库调用 onwrite 事件侦听器函数?

functions.firestore
    .document('users/00QAGyS0NqFdDSS78E6r')
    .onWrite(event => {

        const commentId = event.params.commentId;
        const postId = event.params.postId;

        // ref to the parent document
        const docRef = admin.firestore().collection('posts').doc();

        // get all comments and aggregate
        return docRef.collection('comments').orderBy('createdAt', 'desc')
            .get()
            .then(querySnapshot => {

                // get the total comment count
                const commentCount = querySnapshot.size

                const recentComments = []

                // add data from the 5 most recent comments to the array
                querySnapshot.forEach(doc => {
                    recentComments.push( doc.data() )
                });

                recentComments.splice(5)

                // record last comment timestamp
                const lastActivity = recentComments[0].createdAt

                // …
Run Code Online (Sandbox Code Playgroud)

firebase google-cloud-firestore

2
推荐指数
1
解决办法
826
查看次数

标签 统计

firebase ×1

google-cloud-firestore ×1