TypeError:无法读取属性' val'未定义的Firebase android

时间:2018-06-12 06:53:58

标签: javascript android node.js firebase elasticsearch

我正在将弹性搜索连接到我的Android项目,但我正在这一步,但每次我在我的应用程序中执行操作时都会收到错误:TypeError:无法读取属性' val'未定义的

以下是NotePad中的代码

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

const request = require('request-promise')

exports.indexPostsToElastic = functions.database.ref('/post/{post_id}')
.onWrite(event => {
    let postData = event.data.val();
    let post_id = event.params.post_id;

    console.log('Indexing post:', postData);

    let elasticSearchConfig = functions.config().elasticsearch;
    let elasticSearchUrl = elasticSearchConfig.url + 'post/post/' + post_id;
    let elasticSearchMethod = postData ? 'POST' : 'DELETE';

    let elasticSearchRequest = {
        method: elasticSearchMethod,
        url: elasticSearchUrl,
        auth:{
            username: elasticSearchConfig.username,
            password: elasticSearchConfig.password,
        },
        body: postData,
        json: true
      };

      return request(elasticSearchRequest).then(response => {
         console.log("ElasticSearch response", response);
         return null;
      });
});

0 个答案:

没有答案