Node won't find mongo nested document called options

I have a document in 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
}

When I use the mongo cli client I can see the chartSettings.options but when I query in Node/Express It doesn't come through. Not sure why and I've confirmed that it isn't JSON.stringify. Here's my express router code:

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

And node express server console:

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

Answers


Fixed - schema wasn't properly defined. In fact, I'd forgotten I was even querying with mongoose.


Need Your Help

How can I get the DataGridRow from the DataRowView?

c# wpf wpfdatagrid

I have created a WPF application that loads 2 DataGrids with data from SqlClient DataTables. I have the method below that compares the two tables. It was working fine, but I must have changed som...

SQL: 2 distinct counts with different where clauses on same field

mysql

How do I combine the 2 queries below into a single query?