如何根据Firebase中的对象获取子项的键

时间:2018-01-31 00:30:13

标签: node.js firebase firebase-realtime-database

我想知道是否有办法使用node.js在firebase中检索_random数字并将其封装在我的通知主体部分中。我试图创建一个数组并从firebase读取所有内容到数组中,但它没有帮助



exports.sendFigureNotification = functions.database.ref('_random').onWrite(event => {
var rootRef = admin.database().ref();
rootRef.once("value", function(snapshot) {

    
});

 const payload = {
        notification: {
            title: 'Title',
            body: 'The Cloud Function works',  //use _random to get figure at index key
            badge: '1',
            sound: 'default'
        }
    };
    
    const options = {
      	priority:"high",
        timeToLive: 60 * 60 * 24, //24 hours
        content_available: true
    };
  	const topic = "HBF"
   console.log('Sending notifications');
    return admin.messaging().sendToTopic(topic, payload, options);
 
});




https://i.stack.imgur.com/t22Ou.png

0 个答案:

没有答案