简体   繁体   English

Mongoose NodeJS macOS Big Sur MongooseServerSelectionError:连接 ECONNREFUSED::1:27017

[英]Mongoose NodeJS macOS Big Sur MongooseServerSelectionError: connect ECONNREFUSED ::1:27017

I'm using brew mongodb-community on macOS Big Sur and can connect to mongo shell with mongosh.我在 macOS Big Sur 上使用 brew mongodb-community,可以使用 mongosh 连接到 mongo shell。 But when I try to run NodeJS and Mongoose app I get MongooseServerSelectionError: connect ECONNREFUSED::1:27017 .但是当我尝试运行 NodeJS 和 Mongoose 应用程序时,我得到MongooseServerSelectionError: connect ECONNREFUSED::1:27017 Why can I connect to mongodb with mongo shell but not NodeJS and Mongoose?为什么我可以使用 mongo shell 连接到 mongodb 而不是 NodeJS 和 Mongoose?

Edit: Sample code from my NodeJS Mongoose code编辑:来自我的 NodeJS Mongoose 代码的示例代码

import mongoose from 'mongoose';
mongoose.connect('mongodb://localhost:27017/mydb', {
    useNewUrlParser: true,
    useUnifiedTopology: true
});

My solution was to use 127.0.0.1 and NOT localhost .我的解决方案是使用127.0.0.1而不是localhost For some reason Mongoose can read mongodb://127.0.0.1:27017/mydb and NOT mongodb://localhost:27017/mydb由于某种原因猫鼬可以读取mongodb://127.0.0.1:27017/mydb而不是mongodb://localhost:27017/mydb

Your MongoDB Server is not up, Try brew services start mongodb-community@6.0.您的 MongoDB 服务器未启动,请尝试 brew services start mongodb-community@6.0。

if not started kindly follow below commands.如果没有开始,请按照以下命令操作。

Step-1: install brew from download brew第 1 步:从下载 brew 安装 brew

" At the end brew shows to add path in your terminal "(which many people forget to add) 最后 brew 显示在您的终端中添加路径”(很多人忘记添加)

For reference, The below commands will appear in your terminal: ==> Next steps:作为参考,以下命令将出现在您的终端中: ==> 后续步骤:

  • Run these three commands in your terminal to add Homebrew to your PATH:在您的终端中运行这三个命令以将 Homebrew 添加到您的 PATH:

echo '# Set PATH, MANPATH, etc., for Homebrew.' echo '# 为 Homebrew 设置 PATH、MANPATH 等。 >> /Users/xxxx/.zprofile >> /Users/xxxx/.zprofile

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/xxxxx/.zprofile echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/xxxxx/.zprofile

eval "$(/opt/homebrew/bin/brew shellenv)"评估“$(/opt/homebrew/bin/brew shellenv)”


Step-2: install MongoDB:第二步:安装MongoDB:

brew install mongodb-community@6.0 brew 安装 mongodb-community@6.0

Step-3: Start MongoDB Server:第三步:启动MongoDB服务器:

brew services start mongodb-community@6.0 brew 服务启动 mongodb-community@6.0

Please refer MongoDB咨询MongoDB

暂无
暂无

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

相关问题 MongooseServerSelectionError:连接 ECONNREFUSED::1:27017 - MongooseServerSelectionError: connect ECONNREFUSED ::1:27017 MongooseServerSelectionError:连接 ECONNREFUSED 127.0.0.1:27017 - MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017 MongooseServerSelectionError:在 windows 7 中连接 ECONNREFUSED 127.0.0.1:27017 - MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017 in windows 7 MongooseServerSelectionError:连接 ECONNREFUSED::1:27017 在 Connection.openUri - MongooseServerSelectionError: connect ECONNREFUSED ::1:27017 at Connection.openUri UnhandledPromiseRejectionWarning:MongooseServerSelectionError:连接 ECONNREFUSED 127.0.0.1:27017 - UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017 在 Docker Compose 中获取“MongooseServerSelectionError:连接 ECONNREFUSED 127.0.0.1:27017” - Getting "MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017" in Docker Compose MongooseServerSelectionError: connect ECONNREFUSED ::1:27017 in node v17 and mongo is running - MongooseServerSelectionError: connect ECONNREFUSED ::1:27017 in node v17 and mongo is running NodeJS和Heroku:连接ECONNREFUSED 127.0.0.1:27017 - NodeJS and Heroku: connect ECONNREFUSED 127.0.0.1:27017 MongooseServerSelectionError:连接 ECONNREFUSED - MongooseServerSelectionError: connect ECONNREFUSED 超时错误 - MongoServerSelectionError:连接 ECONNREFUSED::1:27017 - [NodeJS + MongoDB] - timeoutError - MongoServerSelectionError: connect ECONNREFUSED ::1:27017 - [NodeJS + MongoDB]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM