I'm using Azure Cosmos DB with mongodb backend. I'm keep getting this error.

```
Exception has occurred: Error
TypeError: Cannot read property 'electionId' of undefined
at ReplSetState.update (c:\dev\3dshoppers.backend\node_modules\mongodb-core\lib\topologies\replset_state.js:371:70)
at Server._handleEvent (c:\dev\3dshoppers.backend\node_modules\mongodb-core\lib\topologies\replset.js:421:45)
at Server.g (events.js:291:16)
at emitOne (events.js:96:13)
at Server.emit (events.js:188:7)
at c:\dev\3dshoppers.backend\node_modules\mongodb-core\lib\topologies\server.js:297:14
at c:\dev\3dshoppers.backend\node_modules\mongodb-core\lib\connection\pool.js:457:18
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)

```

I'm using mongodb@2.2.19. If I update the npm package to the latest version, I get different error ('MongoError: pool destroyed'). I think there is some problem with Cosmos DB......

This is happening on this line in replset\_state.js.

```
var currentElectionId = self.set[self.primary.name.toLowerCase()].electionId;

```

EDIT: I was able to reproduce the bug with two files below.

server.js

```
// packages
const express = require('express');
const http = require('http');
const MongoClient = require('mongodb').MongoClient;

// express app
const app = express();
// mongodb
const mongoConnectionString = process.env.MONGODB_CONNECTION_STRING;
const mongoOptions =
{
    connectTimeoutMS: 0
}

var mongoDB;
var myCollection;

MongoClient.connect(mongoConnectionString, (err, db) => {

    if (err) throw err;

    mongoDB = db.db('testdb');

    mongoDB.collection('cars', (err, collection) => {            
            if (err) throw err;            
            myCollection = collection;
        });

        http.createServer(app).listen(process.env.PORT || 3000);
});

```

package.json

```
{
    "name": "mongodb-debug",
    "description": "mongodb debugging",
    "version": "0.0.1",
    "private": true,
    "license": "MIT",
    "author": "me",
    "engines": {
        "node": "6.9.3"
    },
    "dependencies": {
        "express": "4.15.2",
        "mongodb": "2.2.19"
    },
    "scripts": {
        "start": "node server.js",
        "test": "mocha"
    }
}

```