TypeError: Cannot read property 'emails' of null
<p>Here is line 54, where I am getting the error: </p>

<pre><code>if (docr.emails) {
</code></pre>

<p>And here is the rest of my original code:</p>

<pre><code>var MongoClient = require('mongodb').MongoClient;
var assert = require('assert');
var ObjectId = require('mongodb').ObjectID;
var config = require('./config'),
    xlsx = require('./xlsx'),
    utils = require('./utils'),
    _ = require('lodash'),
    url = config.DB_URL;

var meetings = [];

function findNumberOfNotesByMeeting(db, meeting, callback) {
    var meetingId = meeting._id.toString(),
        meetingName = meeting.name.displayValue,
        attendees = meeting.attendees;
        host = meeting.host;

    var count = 1, pending = 0, accepted = 0;
    console.log("==== Meeting: " + meetingName + '====');
    _.each(attendees, function(item) {
      console.log(count++ + ': ' + item.email + ' (' + item.invitationStatus + ')');
      if (item.invitationStatus == 'pending') { pending++; }
      else if (item.invitationStatus == 'accepted') { accepted++; }
    });
    console.log("*** " + attendees.length + ", " + pending + "," + accepted);

    db.collection('users').findOne({'_id': new ObjectId(host)}, function(err, doc) {
        var emails = [];
        if (doc.emails) {
            doc.emails.forEach(function(e) {
                emails.push(e.email + (e.primary ? '(P)' : ''));
            });
        }
        var email = emails.join(', ');
        if (utils.toSkipEmail(email)) {
            callback();
        } else {
            db.collection('notes').find({ 'meetingId': meetingId }).count(function(err, count) {
                if (count != 0) {
                    console.log(meetingName + ': ' + count + ',' + attendees.length + ' (' + email + ')');
                    meetings.push([ meetingName, count, email, attendees.length, pending, accepted ]);
                }
                callback();
            });
        }
    });
}

function findMeetings(db, meeting, callback) {  
    var host = meeting.host;

    db.collection('users').findOne({'_id': new ObjectId(host)}, function(err, docr) {
        var emails = [];
        if (docr.emails) {
            docr.emails.forEach(function(e) {
                emails.push(e.email + (e.primary ? '(P)' : ''));
            });
        }
        var email = emails.join(', ');


        if (utils.toSkipEmail(email)) {
            callback();
        } else {
        var cursor = db.collection('meetings').find({
            'email': {'$regex': 'abc', '$options': 'i' }
        }); 
        }   


    cursor.count(function(err, count) {
        console.log('count: ' + count);
        var cnt = 0;
        cursor.each(function(err, doc) {
            assert.equal(err, null);
            if (doc != null) {
                findNumberOfNotesByMeeting(db, doc, function() {
                    cnt++;
                    if (cnt &gt;= count) { callback(); }
                });
            }
        });
    });
    });
};


MongoClient.connect(url, function(err, db) {
    assert.equal(null, err);
    findMeetings(db, function() {
        var newMeetings = meetings.sort(function(m1, m2) { return m2[1] - m1[1]; });
        newMeetings.splice(0, 0, [ 'Meeting Name', 'Number of Notes', 'Emails' ]);
        xlsx.writeXLSX(newMeetings, config.xlsxFileNameMeetings);
        db.close();
    });
});
</code></pre>