- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将 mongodb 与我在 docker 容器中的应用程序连接起来。我正在使用 Mongoose 包,这是我写的代码
mongoose.connect("mongodb://mongo:27016/IssueTracker", { useNewUrlParser: true,useUnifiedTopology: true },(err: Error) => {
err ? console.log(err) : console.log("Mongodb database connected");
});
docker-compose.yml
文件
version: "3"
services:
app:
container_name: IssueTracker
restart: always
build: .
ports:
- '9000:9000'
links:
- mongo
mongo:
container_name: mongo
image: mongo
ports:
- '27017:27016'
Dockerfile
FROM node:13
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 9000
RUN ["npm","run","dev"]
docker-compose up
在我的 docker cmdline 中
server started on port 9000
MongooseError [MongooseServerSelectionError]: getaddrinfo ENOTFOUND mongo
at new MongooseServerSelectionError (/app/node_modules/mongoose/lib/error/serverSelection.js:22:11)
at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:823:32)
at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:333:15)
at Object.<anonymous> (/app/src/app.ts:9:10)
at Module._compile (internal/modules/cjs/loader.js:1123:30)
at Module.m._compile (/app/node_modules/ts-node/src/index.ts:839:23)
at Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
at Object.require.extensions.<computed> [as .ts] (/app/node_modules/ts-node/src/index.ts:842:12)
at Module.load (internal/modules/cjs/loader.js:972:32)
at Function.Module._load (internal/modules/cjs/loader.js:872:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at main (/app/node_modules/ts-node/src/bin.ts:227:14)
at Object.<anonymous> (/app/node_modules/ts-node/src/bin.ts:513:3)
at Module._compile (internal/modules/cjs/loader.js:1123:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
at Module.load (internal/modules/cjs/loader.js:972:32) {
reason: TopologyDescription {
type: 'Single',
setName: null,
maxSetVersion: null,
maxElectionId: null,
servers: Map(1) { 'mongo:27016' => [ServerDescription] },
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: null
},
[Symbol(mongoErrorContextSymbol)]: {}
}
最佳答案
尝试创建和使用网络而不是 link
version: "3"
services:
app:
container_name: IssueTracker
restart: always
build: .
ports:
- '9000:9000'
networks: #here
- my-network
mongo:
container_name: mongo
image: mongo
ports:
- '27017:27016'
networks: #here
- my-network
networks: #here
my-network:
driver: bridge
关于node.js - docker : MongooseError [MongooseServerSelectionError]: getaddrinfo ENOTFOUND mongo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61539538/
我正在学习这些教程,因为我想从 MongoDB 和 MERN 堆栈开始: https://medium.com/@beaucarnes/learn-the-mern-stack-by-building
我尝试通过 mongoose 驱动程序连接到我的 mongodb Atlas,但它不断抛出 MongooseServerSelectionError,我已经检查了数据库用户的用户名和密码,它是正确的。
当我尝试使用 Mongoose 将我的应用程序与我的数据库连接时遇到问题。已经尝试了我在谷歌上找到的以下解决方案: windows下重启MongoDB服务 使用位于 mongodb 的 bin 文件中
我已经尝试了 2 个多小时,现在试图弄清楚这个数据库有什么问题。我已经尝试了一切。从重新安装服务器、重新启动进程、重新启动等等。尝试连接时它一直给我这个错误: const serverSelectio
更新2 我面临另一个错误 如果我按如下方式使用路径,则会收到“无效的卷规格”错误 甚至将路径更改为“C:/docker-entrypoint-initdb.d /”,init-mongo.sh也不会执
我正在尝试将 mongodb 与我在 docker 容器中的应用程序连接起来。我正在使用 Mongoose 包,这是我写的代码 mongoose.connect("mongodb://mongo:27
我试图通过发布方法将数据保存在mongodb中,并将mongodb atala与node.js结合使用,但它一直给我一个错误,我提供了正确的连接字符串和正确的密码。请就此问题提供帮助。谢谢 here
我下载了 mongoDB,它工作得很好,但是当我想使用 REST API 并在命令行中使用 npm run dev 时,它给了我这个错误。 That's an error (node:10100) U
我是一名优秀的程序员,十分优秀!