【问题标题】:Node won't find mongo nested document called optionsNode 找不到名为 options 的 mongo 嵌套文档
【发布时间】:2016-05-20 01:16:14
【问题描述】:

我在 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"                    
        }                                                  
},              

和节点快递服务器控制台:

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' } } }

【问题讨论】:

  • 数据中的__v 键表明您正在使用猫鼬。架构中如何定义“选项”?可能应该是Mixed

标签: node.js mongodb express


【解决方案1】:

已修复 - 未正确定义架构。事实上,我忘记了我什至用猫鼬查询。

【讨论】:

    猜你喜欢
    • 2022-01-17
    • 2013-11-24
    • 1970-01-01
    • 2020-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-20
    • 1970-01-01
    相关资源
    最近更新 更多