Atlas deployments connect doesn't work locally

I want to connect to local atlas deployment, but I’m failing to do so. I’m using Atlas CLI.

What i did so far is: atlas deployments setup
After that i run the command: atlas deployments connect
In interactive shell i have options to select a deployment, i choose local one.
Next, i have 3 options: mongosh, compass, connectionString.
Mongosh and compass work, but in order to connect programmatically from my node.js app i have to choose the “connectionString”.
The string it generates is: "mongodb://localhost:27017/?directConnection=true".

Now, i use mongodb node.js driver to connect but it fails to connect.
Am i missing something here? What is the “connectionString” option for otherwise?


If instead of choosing mongosh in the list you choose connectionString and manually connect with mongosh, does it work? i.e.

mongosh "mongodb://localhost:27017/?directConnection=true"

if that does work, there might be some issues in your code.

Hi Massimiliano,

Thanks for prompt reply!
I tried that but it doesn’t work.
I’m just getting no matches found: mongodb://localhost:27017/?directConnection=true

However when i choose mongosh as connecting method, the url it generates is this one:
It does connect, but when i try that one manually with mongosh i’m getting parse error near "&"

Actually it works when i put double quotes.
I was following the docs to setup Atlas in Docker, there was without quotes. But the docker setup didn’t work, but that’s another topic. Programmatically i can’t access using mongodb node.js driver, but mongosh and compass both work.

Is the node.js application running on the same host as mongosh/Compass? Or are you running it in Docker, Docker compose, or in some other configuration?

I tried both, but it works now when using Docker, just instead of localhost i had to use “mongo” same as it’s defined in docker-compose. So it works now, thanks! :slight_smile:

I am getting following error… ? How do you want to set up your local Atlas deployment? default

Creating your cluster local6034

1/2: Starting your local environment…

2/2: Creating your deployment local6034…

Error: failed to connect to mongodb server: server selection error: server selection timeout, current topology: { Type: Single, Servers: [{ Addr: localhost:27017, Type: Unknown, Last error: dial tcp connect: connection refused }, ] }

macpro@MacPros-Mac-Pro ~ % mongod start

zsh: command not found: mongod

macpro@MacPros-Mac-Pro ~ % mongod

zsh: command not found: mongod

macpro@MacPros-Mac-Pro ~ % mongodb

zsh: command not found: mongodb

macpro@MacPros-Mac-Pro ~ % mongo

zsh: command not found: mongo

macpro@MacPros-Mac-Pro ~ % mongod --config /usr/local/etc/mongod.conf

zsh: command not found: mongod

macpro@MacPros-Mac-Pro ~ % mongosh “mongodb://localhost:27017/?directConnection=true”

Current Mongosh Log ID: 664f42c163f0a60fd9600254

Connecting to: mongodb://localhost:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.2.6

MongoNetworkError: connect ECONNREFUSED, connect ECONNREFUSED ::1:27017

macpro@MacPros-Mac-Pro ~ %