简体   繁体   中英

Can't connect to mongodb atlas nodejs

I've been trying to connect to an atlas DB using mongoose

const mongoose = require('mongoose');
const my_db =
    'mongodb+srv://adminUser:admisPassword@impact-9hs0w.mongodb.net/test?retryWrites=true&w=majority';
mongoose
    .connect(my_db, {
        useUnifiedTopology: true,
        useNewUrlParser: true
    })
    .then((result) => {
        console.log(result);
        const server = app.listen(8080, () => {
            console.log('listening... ');
        });
    })
    .catch((err) => {
        console.log(err);
    });

but it stays [nodemon] starting 'node app.js' for a while then it gives this log message

Error: queryTxt ETIMEOUT impact-9hs0w.mongodb.net at QueryReqWrap.onresolve [as oncomplete] (dns.js:206:19) { errno: undefined, code: 'ETIMEOUT', syscall: 'queryTxt',
hostname: 'impact-9hs0w.mongodb.net' }

I whitelisted all IPs but it still won't connect

After contacting support they told me to use the legacy connection link as so Using the legacy link

Make sure your roles and passwords are set correctly in the link, for me the admin user just wasn't working, so I made a new one and it fixed my issue.

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