1

我試圖使用Firebase函數實現觸發器,該觸發器重複數據庫中的某些數據。我想在votes/user/vote觀看所有添加的結構是:未調用Firebase函數onWrite

enter image description here

我試過的代碼是:

const functions = require('firebase-functions'); 
const admin = require('firebase-admin'); 

admin.initializeApp(functions.config().firebase); 

exports.duplicateFeedback = functions.database.ref('/votes/{userId}/voteId') 
    .onWrite(event => { 
     const userId = event.params.userId; 
     const voteId = event.data.key(); 
     const vote = event.data.val(); 
     console.log(`New feedback from user ${userId}: { description: "${vote.feedback}", score: ${vote.rating}}`); 

     return; 
    }); 

但我甚至無法得到它的觸發。任何線索是什麼我的功能錯了?我敢打賭,這與參考文獻有關,但我無法弄清楚究竟是什麼。

回答

3

眼下,該功能是通過寫觸發

exports.duplicateFeedback = functions.database.ref('/votes/{userId}/voteId') 

這將通過這樣的事情被觸發:

votes: { 
    00000_josemi_foo: { 
     voteId: { 
      // data 
     } 
    } 
} 

但你不找孩子voteId,你'尋找{userId}的任何孩子,如-33,所以你需要使用通配符:

exports.duplicateFeedback = functions.database.ref('/votes/{userId}/{voteId}') 
相關問題