繁体   English   中英

使用猫鼬连接到MongoDb Atlas

[英]Connecting to MongoDb Atlas using mongoose

我正在尝试使用atlas提供的URL字符串连接到MongoDb Atlas:

mongoose
  .connect(
    "mongodb+srv://user:@contactlistcluster-hk1w5.mongodb.net/test?retryWrites=true"
  )
  .then(() => {
    console.log("Connected to database!");
  })
  .catch((error) => {
    console.log("Connection failed!");
    console.log(error);
  });

但是我在运行时遇到此错误:

**TypeError: Cannot read property 'close' of undefined
    at topology.connect (C:\dev\contact-api_bind\node_modules\mongoose\node_modules\mongodb\lib\operations\mongo_client_ops.js:412:16)
    at ReplSet.<anonymous> (C:\dev\contact-api_bind\node_modules\mongoose\node_modules\mongodb\lib\topologies\replset.js:364:11)
    at Object.onceWrapper (events.js:255:19)
    at ReplSet.emit (events.js:160:13)
    at C:\dev\contact-api_bind\node_modules\mongodb-core\lib\topologies\replset.js:631:23
    at Server.<anonymous> (C:\dev\contact-api_bind\node_modules\mongodb-core\lib\topologies\replset.js:357:9)
    at Object.onceWrapper (events.js:255:19)
    at Server.emit (events.js:160:13)
    at Pool.<anonymous> (C:\dev\contact-api_bind\node_modules\mongodb-core\lib\topologies\server.js:562:21)
    at Pool.emit (events.js:160:13)
    at Connection.<anonymous> (C:\dev\contact-api_bind\node_modules\mongodb-core\lib\connection\pool.js:316:12)
    at Object.onceWrapper (events.js:255:19)
    at Connection.emit (events.js:160:13)
    at TLSSocket.<anonymous> (C:\dev\contact-api_bind\node_modules\mongodb-core\lib\connection\connection.js:245:50)
    at Object.onceWrapper (events.js:255:19)
    at TLSSocket.emit (events.js:160:13)
[nodemon] app crashed - waiting for file changes before starting...**

问题已解决。 实际上,我的组织正在使用代理服务器来阻止连接。

在我的个人计算机上工作得很好。

暂无
暂无

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

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