Firestore函数不会在事件上触发

时间:2018-03-15 13:48:53

标签: node.js firebase google-cloud-firestore firebase-cli

Firestore Cloud Functions不会触发事件,我的函数不会触发onCreate,onUpdate,onDelete或onWrite。 JS脚本成功地推送到firestore。

数据库设计:

-|search
    -|searchId
        -|id: string
        -|name: sting
        -|img: string

规则:

match /search/{searchId}{
    allow read;
    allow write: if request.auth != null;
}


const functions = require('firebase-functions');
const admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);

exports.updateIndex = functions.database.ref('/search/{searchId}').onWrite(event => {
    console.log('Working')
}

1 个答案:

答案 0 :(得分:2)

由于您使用的是firestore,因此以上操作无效。您在问题中的功能是firebase而不是firestore,将其更改为:

exports.updateIndex = functions.firestore.document('search/{searchId}').onWrite(event => {
console.log('Working');
});

更多信息:

https://firebase.google.com/docs/functions/firestore-events

相关问题