简体   繁体   English

Azure Cosmos DB:TypeError:无法读取undefined的属性'electionId'

[英]Azure Cosmos DB: TypeError: Cannot read property 'electionId' of undefined

I'm using Azure Cosmos DB with mongodb backend. 我正在使用带有mongodb后端的Azure Cosmos DB。 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. 我正在使用mongodb@2.2.19。 If I update the npm package to the latest version, I get different error ('MongoError: pool destroyed'). 如果我将npm包更新到最新版本,我会得到不同的错误('MongoError:pool destroyed')。 I think there is some problem with Cosmos DB...... 我认为Cosmos DB存在一些问题......

This is happening on this line in replset_state.js. 这发生在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 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 的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"
    }
}

You can avoid the issue by removing the &replicaSet=globaldb from the connection string if you are not using a replica set and only have a single Cosmos DB instance. 如果您没有使用副本集并且只有一个Cosmos数据库实例,则可以通过从连接字符串中删除&replicaSet=globaldb来避免此问题。

The similar issue could be found here: MongoError: Pool Destroyed . 类似的问题可以在这里找到: MongoError:Pool Destroyed

I have exactly the same error: 我有完全相同的错误:

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)

also using cosmos-db with my node-js application. 也使用cosmos-db和我的node-js应用程序。 The connection works fine because all my collection where created 连接工作正常,因为我创建的所有集合

hier is the package.json and the complete project hier是package.json和完整的项目

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM