TypeError:无法读取未定义的属性“ val”(即使进行了所有更改)

时间:2019-03-18 06:35:15

标签: node.js firebase elasticsearch firebase-realtime-database

很抱歉再次提出这个问题,但我尝试了所有解决方案,但仍然遇到此错误。我正在将elastic search连接到我的Android项目。我被困在这里,我已经尝试了一切。

错误快照:

This is  the snapshot of the error

这是我的index.js文件,我进行了所有更改,但仍然收到错误。

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

const request = require('request-promise')

exports.indexPostsToElastic = functions.database.ref('/posts/{post_id}')
.onWrite(( change,context) => {
    let postData = change.after.val();
    let post_id = context.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);
      });
});

这是我的package.json文件的代码

{
 "name": "functions",
 "description": "Cloud Functions for Firebase",
 "scripts": {
 "serve": "firebase serve --only functions",
 "shell": "firebase functions:shell",
 "start": "npm run shell",
 "deploy": "firebase deploy --only functions",
 "logs": "firebase functions:log"
  },
 "dependencies": {
 "firebase-admin": "~7.0.0",
 "firebase-functions": "^2.2.0",
 "request": "^2.88.0",
 "request-promise": "^4.2.4"
 },
 "private": true
 }

这是我的数据库的快照

wiki

0 个答案:

没有答案