TypeError:无法在Android中读取未定义Firebase的属性“val”

时间:2018-04-25 20:21:24

标签: javascript node.js firebase elasticsearch

我在Firebase项目和服务中使用Google Cloud服务,我使用的是Elasticsearch。所以,我已经在我的Firebase项目上成功部署了该项目,但问题是每当我触发我的函数时,这都是我的firebase功能日志中的错误 -

img.rot90()

这是我写的index.js文件:

TypeError: Cannot read property 'val' of undefined
at exports.indexPostsToElastic.functions.database.ref.onWrite.event (/user_code/index.js:13:27)
at Object.<anonymous> (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:112:27)
at next (native)
at /user_code/node_modules/firebase-functions/lib/cloud-functions.js:28:71
at __awaiter (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:24:12)
at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:82:36)
at /var/tmp/worker/worker.js:710:26
at process._tickDomainCallback (internal/process/next_tick.js:135:7)

这是我的package.json文件:

const functions = require('firebase-functions');
const request = require('request-promise')
exports.indexPostsToElastic = functions.database.ref('/posts/{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 + 'posts/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 个答案:

没有答案