简体   繁体   中英

Error in connecting node.js app to mongoDb Atlas database

When I try to connect my node.js application with mongodb atlas where I have created a database named test I get the following error in console.

Error: queryTxt ETIMEOUT cluster0.z7ysr.mongodb.netat QueryReqWrap.onresolve [as oncomplete]

I have a free tier atlas account. I have used the mongoose library and the following code in my project.

mongoose.connect('mongodb+srv://username:pwd@cluster0.z7ysr.mongodb.net/testretryWrites=true&w=majority'
{
    useNewUrlParser: true,
    useUnifiedTopology: true
});

Use,(comma). You missed a comma after Mongo URI string.

let db='mongodb+srv://username:pwd@cluster0.z7ysr.mongodb.net/testretryWrites=true&w=majority'
//Used comma below.
mongoose.connect(db,{
    useNewUrlParser: true,
    useUnifiedTopology: true
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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