我遇到了一个问题,我尝试解决了很长时间。我正在尝试从nodejsvia连接到 Mongo Atlas 云mongoose。这不是我第一次,但我就是找不到答案。
猫鼬版本:5.9.22
这是我的代码:
const express = require('express')
const mongoose = require('mongoose')
const bodyparser = require('body-parser')
const app = express()
app.use(bodyparser.json())
mongoose.connect("mongodb+srv://dudvil1:password@cluster0.guxmm.mongodb.net/shopping_list?
retryWrites=true&w=majority", {
useNewUrlParser: true,
useUnifiedTopology: true
})
useNewUrlParser: true,
useUnifiedTopology: true
})
.then(() => console.log('mongo connected'))
.catch(err => console.log(err));
const port = process.env.PORT || 5000
app.listen(port, () => console.log(`server started in port ${port}`))
Run Code Online (Sandbox Code Playgroud)
我的白名单设置只包括 0.0.0.0/0 我在数据库访问中的用户名和密码很简单,没有任何特殊字符,但总是得到同样的错误:
MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is …Run Code Online (Sandbox Code Playgroud)