mongodb 백엔드에서 Azure Cosmos DB를 사용하고 있습니다. 이 오류가 계속 발생합니다.Azure Cosmos DB : TypeError : 정의되지 않은 'electionId'속성을 읽을 수 없습니다.
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)
저는 [email protected]를 사용하고 있습니다. 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"
}
}
더 많은 코드가 필요합니다. 분명히'self.set [self.primary.name.toLowerCase()]'는 'undefined'로 평가되고 따라서 오류가 발생합니다. 왜?에 관해서는, 우리는 당신이하고있는 일을 더 많이 볼 필요가 있습니다. 도움말 섹션에서 [mcve] (https://stackoverflow.com/help/mcve)를 참조하십시오. 전체 프로그램을 볼 필요가 없기 때문입니다. 문제를 재현하는 데 필요한 최소한의 것입니다. –
더 중요한 것은 라이브러리를 디버깅하는 데 ** ** 관련되지 않습니다. 그것들은 제비 뽑기와 많은 사람을 위해 완전하게 일한다. 뭔가 잘못 됐어. 잘못된 자격 증명, 잘못된 연결 문자열 등 –
내 연결 문자열은? ssl = true & replicaSet = globaldb로 끝납니다. – 3irhui34t34