Я создал облачную функцию Firebase, которая ищет пользователей, у которых значение IsNotificationEnabled равно true.Часть моей функции
export const sendPushNotification = functions.https
.onRequest(async (req, res) => {
try {
const { message } = req.body;
var usersRef = firebase.ref('/Users');
var usersPushNotificationTokensRef = firebase.ref('/PushNotificationTokens')
var listUsersSendNotifications = [],
usersWithTokenSendNotifications = [],
promises = [];
if (message) {
await usersRef.orderByChild('IsNotificationEnabled').equalTo(true).once('value', (snapshot) => {
snapshot.forEach((childSnapshot) => {
console.log(childSnapshot.key)
listUsersSendNotifications.push(childSnapshot.key)
return false;
})
})
..........................
, как вы можете видеть здесь, я ищу пользователей, где IsNotificationEnabled = true.когда я запускаю его, я получаю в логах
[2018-05-22T09: 12: 57.352Z] @ firebase / database: FIREBASE WARNING: Использование неопределенного индекса.Ваши данные будут загружены и отфильтрованы на клиенте.Для повышения производительности рассмотрите возможность добавления «.indexOn»: «IsNotificationEnabled» в / Users к своим правилам безопасности.
правила, которые я вставляю в консоль firebase
{
"rules": {
".indexOn": ["IsNotificationEnabled"],
"Users":{
"$uid":{
".indexOn": ["IsNotificationEnabled"],
".write": "$uid === auth.uid",
".read": "$uid === auth.uid"
}
},
".read": true,
".write": true
}
}