我在MongoDB中有一个文档:
{
"_id": "56aa92d81a4bfbec1c8ed8e2",
/* other attributes */
"chartSettings": {
"title": {
"text": "Student Grouped by Credit Load"
},
"yAxis": {
"title": "Students"
},
"xAxis": {
"title": "Credit Load"
},
"options": {
"chart": {
"type": "areaspline"
}
}
},
/* other attributes */
"data": [
/* array of data objects */
],
"__v": 7
}
当我使用mongo cli客户端时,我可以看到chartSettings.options
但是当我在Node / Express中查询时它没有通过。不确定为什么,我已经确认它不是JSON.stringify
。这是我的快递路由器代码:
reports.find({}, function (err, reports) {
if (err) return res.send('Error: '+err);
console.log(reports[0].chartSettings); //console shows options: {}
res.send(JSON.stringify(reports));
});
MongoClient:
"chartSettings" : {
"options" : {
"chart" : {
"type" : "column"
}
},
"title" : {
"text" : "Student Grouped by Credit Load"
},
"yAxis" : {
"title" : "Students"
},
"xAxis" : {
"title" : "Credit Load"
}
},
和node express服务器控制台:
GET /data/mongo/reports/ 200 12.466 ms - 5732
{ options: {},
title: { text: 'Student Grouped by Credit Load' },
yAxis: { title: 'Students' },
xAxis: { title: 'Credit Load' },
opts: { chart: { type: 'areaspline' } } }
答案 0 :(得分:0)
已修复 - 架构尚未正确定义。事实上,我忘记了我甚至用猫鼬来查询。