[英]Firebase Firestore - unable to get the value of a field in a collection
I have a Firebase Firestore defined as shown in the image 我有一个如图所示的Firebase Firestore
The field zaaidata is an object. zaaidata字段是一个对象。 I want to use the value of tot and van in a response that is sent to my chatbot in Dialogflow with a webhook.
我想在通过webhook发送到Dialogflow中我的聊天机器人的响应中使用tot和van的值。
I managed to query the document, but I am unable to retrieve the specific values. 我设法查询了文档,但是无法检索特定值。 I already tried this:
我已经试过了:
Here is my index.js 这是我的index.js
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
var db = admin.firestore();
exports.webhook = functions.https.onRequest((req, res) => {
let parameters = req.body.result.parameters;
var groentenRef = db.collection('groenten').doc(parameters.groente);
var query = groentenRef.get()
.then(doc => {
if (!doc.exists) {
response = "No such document!";
} else {
response = "Je kan zaaien tussen " + doc.data["zaaidata"]["van"] + " en " + doc.data["zaaidata"]["tot"];
}
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify({ "speech": response, "displayText": response}));
})
.catch(err => {
console.log('Error getting documents', err);
});
});
Can someone help me on this, please? 有人可以帮我吗? Thanks!
谢谢!
你尝试过这个吗
response = "Je kan zaaien tussen " + doc.data().zaaidata.van + " en " + doc.data().zaaidata.tot;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.