Azure Cosmos DB: TypeError: cannot read property 'electionId' from undefined

I am using Azure Cosmos DB with the mongodb backend. I 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 am using mongodb@2.2.19. If I upgrade the npm package to the latest version, I get another error ("MongoError: pool destroy"). I think there is some kind of problem with DB Cosmos ...

This happens on this line in the replset_state.js file.

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

EDIT: I was able to reproduce the error 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"
    }
}
+4
source share
2 answers

, &replicaSet=globaldb , Cosmos DB.

: MongoError: Pool Destroyed.

+4

:

Thu May 25 2017 05:17:57 GMT+0000 (Coordinated Universal Time): Application has thrown an uncaught exception and is terminated:
TypeError: Cannot read property 'electionId' of undefined
    at ReplSetState.update (D:\home\site\wwwroot\node_modules\mongoose\node_modules\mongodb-core\lib\topologies\replset_state.js:353:70)
    at Server.<anonymous> (D:\home\site\wwwroot\node_modules\mongoose\node_modules\mongodb-core\lib\topologies\replset.js:393:45)
    at Server.g (events.js:291:16)
    at emitOne (events.js:96:13)
    at Server.emit (events.js:188:7)
    at D:\home\site\wwwroot\node_modules\mongoose\node_modules\mongodb-core\lib\topologies\server.js:280:14
    at D:\home\site\wwwroot\node_modules\mongoose\node_modules\mongodb-core\lib\connection\pool.js:455:18
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)
TypeError: Cannot read property 'electionId' of undefined
    at ReplSetState.update (D:\home\site\wwwroot\node_modules\mongoose\node_modules\mongodb-core\lib\topologies\replset_state.js:353:70)
    at Server.<anonymous> (D:\home\site\wwwroot\node_modules\mongoose\node_modules\mongodb-core\lib\topologies\replset.js:393:45)
    at Server.g (events.js:291:16)
    at emitOne (events.js:96:13)
    at Server.emit (events.js:188:7)
    at D:\home\site\wwwroot\node_modules\mongoose\node_modules\mongodb-core\lib\topologies\server.js:280:14
    at D:\home\site\wwwroot\node_modules\mongoose\node_modules\mongodb-core\lib\connection\pool.js:455:18
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)

-db node -js. , ,

hier - package.json

https://github.com/aumanjoa/chronas-community/blob/master/package.json#L48 https://github.com/aumanjoa/chronas-community/

0

Source: https://habr.com/ru/post/1677810/


All Articles