Azure Cosmos DB: TypeError: Cannot read property 'electionId' of undefined
Azure Cosmos DB: TypeError: Cannot read property 'electionId' of undefined
我正在使用带有 mongodb 后端的 Azure Cosmos DB。我一直收到此错误。
Exception has occurred: Error
TypeError: Cannot read property 'electionId' of undefined
at ReplSetState.update (c:\devdshoppers.backend\node_modules\mongodb-core\lib\topologies\replset_state.js:371:70)
at Server._handleEvent (c:\devdshoppers.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:\devdshoppers.backend\node_modules\mongodb-core\lib\topologies\server.js:297:14
at c:\devdshoppers.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)
我正在使用 mongodb@2.2.19。如果我将 npm 包更新到最新版本,我会收到不同的错误 ('MongoError: pool destroyed')。我觉得 Cosmos DB 有问题......
这发生在 replset_state.js 的这条线上。
var currentElectionId = self.set[self.primary.name.toLowerCase()].electionId;
编辑:我能够用下面的两个文件重现该错误。
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"
}
}
我有完全相同的错误:
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)
也在我的 node-js 应用程序中使用 cosmos-db。
连接工作正常,因为我所有的 collection 都是在
中创建的
他是 package.json 和完整的项目
https://github.com/aumanjoa/chronas-community/blob/master/package.json#L48
https://github.com/aumanjoa/chronas-community/
如果您不使用副本集并且只有一个 Cosmos DB 实例,则可以通过从连接字符串中删除 &replicaSet=globaldb
来避免此问题。
可以在此处找到类似的问题:MongoError: Pool Destroyed。
我正在使用带有 mongodb 后端的 Azure Cosmos DB。我一直收到此错误。
Exception has occurred: Error
TypeError: Cannot read property 'electionId' of undefined
at ReplSetState.update (c:\devdshoppers.backend\node_modules\mongodb-core\lib\topologies\replset_state.js:371:70)
at Server._handleEvent (c:\devdshoppers.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:\devdshoppers.backend\node_modules\mongodb-core\lib\topologies\server.js:297:14
at c:\devdshoppers.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)
我正在使用 mongodb@2.2.19。如果我将 npm 包更新到最新版本,我会收到不同的错误 ('MongoError: pool destroyed')。我觉得 Cosmos DB 有问题......
这发生在 replset_state.js 的这条线上。
var currentElectionId = self.set[self.primary.name.toLowerCase()].electionId;
编辑:我能够用下面的两个文件重现该错误。
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"
}
}
我有完全相同的错误:
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)
也在我的 node-js 应用程序中使用 cosmos-db。 连接工作正常,因为我所有的 collection 都是在
中创建的他是 package.json 和完整的项目
https://github.com/aumanjoa/chronas-community/blob/master/package.json#L48 https://github.com/aumanjoa/chronas-community/
如果您不使用副本集并且只有一个 Cosmos DB 实例,则可以通过从连接字符串中删除 &replicaSet=globaldb
来避免此问题。
可以在此处找到类似的问题:MongoError: Pool Destroyed。