我一直在尝试将一些代码从实时数据库转换到firestore几天,而没有太多关于它的教程文档。请帮忙。
实时
return admin.database().ref('fcm_token').once('value').then(deviceTokens => {
if (deviceTokens.val()) {
console.log(deviceTokens.val());
const tokens = Object.keys(deviceTokens.val());
console.log(tokens);
return admin.messaging().sendToDevice(tokens, payload);
}
else {
console.log('No token available');
}
})
Firestore Attempt
return functions.firestore.document('fcm_token/{Id}').get().then(deviceTokens => {
if (deviceTokens.val()) {
console.log(deviceTokens.val());
const tokens = Object.keys(deviceTokens.val());
console.log(tokens);
return admin.messaging().sendToDevice(tokens, payload);
}
else {
console.log('No token available');
}
})
Firestore结构
撷取画面