question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Couldn’t connect with atlas database

See original GitHub issue

when I tried to connect to an atlas database using:

import { MongoClient } from "https://deno.land/x/mongo@v0.21.0/mod.ts";
const client = new MongoClient();
await client.connect(
	"mongodb+srv://Eyoatam:" +
		Deno.env.get("MONGO_ATLAS_PASSWORD") +
		"@cluster0.xrb4d.mongodb.net/<dbname>?retryWrites=true&w=majority"
);

It threw the following error:

error: Uncaught (in promise) Error: failed to lookup address information: nodename nor servname provided, or not known
    at processResponse (deno:core/core.js:223:11)
    at Object.jsonOpAsync (deno:core/core.js:240:12)
    at async Object.connect (deno:cli/rt/30_net.js:224:13)
    at async MongoClient.connect (client.ts:41:14)
    at async app.ts:4:1

is there another way to connect with mongodb atlas?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:22 (7 by maintainers)

github_iconTop GitHub Comments

14reactions
berkaygurecommented, Jan 31, 2021

Hi everyone, I was trying to connect to the Atlas database. I have tried all the possible solutions above. finally, I can connect with this way

await client.connect({
    db:'<db>',
    tls:true,
    servers: [
        {
            host: 'cluster0-shard-00-02.soz4m.mongodb.net',
            port: 27017
        }
    ],
    credential: {
        username:"<username>",
        password: '<pwd>',
        db: '<db>',
        mechanism:'SCRAM-SHA-1'
    }
})

1reaction
berkaygurecommented, Feb 13, 2021

You should set your primary cluster address to host. After that, It should connect successfully. I think you are getting an error while finding objects.

Can you try this? It works for me.

interface Room {
  _id?: { $oid: string };
  name: string;
  owner_id: string;
}

const rooms = db.collection<Room>('rooms');
const myRoom = rooms.find({}, {
      noCursorTimeout: false,
} as any);

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot Connection Issues — MongoDB Atlas
Connecting IP address not in IP Access List. Before connecting to your Atlas database deployment, check that you added your host's IP address...
Read more >
"Could not connect to any servers in your MongoDB Atlas ...
In your Mongo project, go to the network access section, and edit the IP to allow access from anywhere (0.0.0.0/0). Ensure that strong ......
Read more >
Couldn't connect with atlas database · Issue #172 - GitHub
when I tried to connect to an atlas database using: import { MongoClient } from "https://deno.land/x/mongo@v0.21.0/mod.ts"; const client ...
Read more >
Error on atlas-debug server app - Database: JIRA c...
Hello everyone, I'm trying atlas-debug for an existing JIRA plugin ... Error on atlas-debug server app - Database: JIRA couldn't connect to ...
Read more >
MongoDB failed to connect - DatabaseFAQs.com
As you can see, when we try to connect to the server we got the error “couldn't connect to the server”. To resolve...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found