gpt4 book ai didi

node.js - Azure Cosmos DB : TypeError: Cannot read property 'electionId' of undefined

转载 作者:可可西里 更新时间:2023-11-01 09:12:55 26 4
gpt4 key购买 nike

我正在使用 Azure Cosmos DB 和 mongodb 后端。我不断收到此错误。

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:池被破坏”)。我认为 Cosmos DB 存在一些问题......

这发生在 replset_state.js 的这一行。

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

编辑:我能够使用下面的两个文件重现该错误。

服务器.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"
}
}

最佳答案

如果您不使用副本集并且只有一个 Cosmos DB 实例,则可以通过从连接字符串中删除 &replicaSet=globaldb 来避免此问题。

类似的问题可以在这里找到:MongoError: Pool Destroyed

关于node.js - Azure Cosmos DB : TypeError: Cannot read property 'electionId' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44148718/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com