TypeError: Невозможно прочитать свойство 'from' из неопределенного в admin.firestore.collection.doc.collection.doc.get.then.queryResult - PullRequest
0 голосов
/ 07 февраля 2019

Так что я схожу с ума по этому поводу: / Я пытаюсь использовать функции Firebase для отправки уведомлений между пользователями.

Функция, кажется, в порядке и успешно находит путь (проверил его в журнале)но все же при попытке доступа к документу возвращается «нет документа», даже если он существует.Я прошел через несколько похожих вопросов, но не нашел решения, пожалуйста, помогите:)

Это функция:

'use-strict'

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

exports.sendNotification = functions.firestore.document("users/{user_id}/notifications/{notification_id}").onWrite((change,context) =>{ 

    const user_id = context.params.user_id;
    const notification_id = context.params.notification_id;
    console.log("User ID: " + user_id + " | Notification ID: " + notification_id);

    return admin.firestore().collection("users").doc(user_id).collection("notifications").doc("notification_id").get().then(queryResult =>{
            if (!queryResult.exists) {
                    console.log('No documents');
                    return null;

            }else{
                const from_user_id = queryResult.data().from;

                const from_data = admin.firestore().collection("users").doc(from_user_id).get();
                const to_data = admin.firestore().collection("users").doc(user_id).get();

                return Promise.all([from_data, to_data]).then(result =>{

                    const from_name = reuslt[0].data().name;
                    const to_name = reuslt[1].data().name;

                    console.log("FROM: " + from_name + " TO: " + to_name);
                    return null;
                });
            }
    }).catch(err =>{ console.error('Error getting document', err); }); });

и это из базы:

1: 00: 23.767 AM Выполнение функции sendNotification заняло 189 мс, и завершилось со статусом: «error»

1: 00: 23.762 AMsendNotification TypeError: Невозможно прочитать свойство «from» из undefined at admin.firestore.collection.doc.collection.doc.get.then.queryResult (/user_code/index.js:15:44) в process._tickDomainCallback (внутренняя / process / next_tick.js: 135: 7)

1: 00: 23.585 AM SendNotification ID пользователя: mpIfC6Ca41eBdwNzwwX3GJaHIfb2 |Идентификатор уведомления: v89cRRcV2np8IsAwbRu0

1: 00: 23.578 AM Запущено выполнение функции sendNotification

1 Ответ

0 голосов
/ 07 февраля 2019

Писал ("tification_id ") в пути вместо (messages_id), как в const, который я создал.

Только 2 часа, чтобы понять это: |

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...