# Can't connect to mongoDB with replit

**URL:** <https://forum.freecodecamp.org/t/cant-connect-to-mongodb-with-replit/599536>\
**Category:** General\
**Created:** [March 20, 2023, 2:43pm UTC](https://forum.freecodecamp.org/t/cant-connect-to-mongodb-with-replit/599536 "2023-03-20T14:43:58Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![charltonjones.fj](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/charltonjones.fj/32/310594_2.png) [@charltonjones.fj](https://forum.freecodecamp.org/u/charltonjones.fj)\
**Post date:** [March 20, 2023, 2:43pm UTC](https://forum.freecodecamp.org/t/cant-connect-to-mongodb-with-replit/599536/1 "2023-03-20T14:43:58Z")

</div>

PLeeeeeeease help, URI is malformed.  
I have whitelisted all IP’s and given the user read and write access. I have also tried using a newer version of mongoose in package.json. I have tried the mongo connection uri with and without database names that do and don’t exist yet.  
I am dyyyyyiiiiinnnnnggg

---

<div class="post-metadata">

**Author:** ![igorgetmeabrain](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/igorgetmeabrain/32/314517_2.png) [@igorgetmeabrain](https://forum.freecodecamp.org/u/igorgetmeabrain)\
**Post date:** [March 20, 2023, 2:52pm UTC](https://forum.freecodecamp.org/t/cant-connect-to-mongodb-with-replit/599536/2 "2023-03-20T14:52:00Z")

</div>

Did you follow this startup guide (which is linked in the challenge description)?

> **[MongoDB Atlas Tutorial – How to Get Started](https://www.freecodecamp.org/news/get-started-with-mongodb-atlas/)**
>
> For the following challenges, you are going to use MongoDB to store data. To simplify the configuration, you'll use a service called MongoDB Atlas. Create a MongoDB Atlas Account MongoDB Atlas is a MongoDB Database-as-a-Service platform, which means...

Also, if your username/password contains any special characters they may need to be percent encoded:

> **[Connection String URI Format — MongoDB Manual](https://www.mongodb.com/docs/manual/reference/connection-string/)**

---

<div class="post-metadata">

**Author:** ![charltonjones.fj](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/charltonjones.fj/32/310594_2.png) [@charltonjones.fj](https://forum.freecodecamp.org/u/charltonjones.fj)\
**Post date:** [March 20, 2023, 2:53pm UTC](https://forum.freecodecamp.org/t/cant-connect-to-mongodb-with-replit/599536/3 "2023-03-20T14:53:44Z")

</div>

Yes I did all the steps (:

---

<div class="post-metadata">

**Author:** ![igorgetmeabrain](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/igorgetmeabrain/32/314517_2.png) [@igorgetmeabrain](https://forum.freecodecamp.org/u/igorgetmeabrain)\
**Post date:** [March 20, 2023, 2:58pm UTC](https://forum.freecodecamp.org/t/cant-connect-to-mongodb-with-replit/599536/4 "2023-03-20T14:58:28Z")

</div>

Can you show me your URI, with the username and password redacted? I guess it’s stored in your Secrets tab in replit?

---

<div class="post-metadata">

**Author:** ![charltonjones.fj](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/charltonjones.fj/32/310594_2.png) [@charltonjones.fj](https://forum.freecodecamp.org/u/charltonjones.fj)\
**Post date:** [March 20, 2023, 3:01pm UTC](https://forum.freecodecamp.org/t/cant-connect-to-mongodb-with-replit/599536/5 "2023-03-20T15:01:11Z")

</div>

I solved it, thank you so much.  
It turns out the original password I had made had a bunch of special characters. I guess these were not translated properly when being used in replit.

---

<div class="post-metadata">

**Author:** ![drizzt32](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/drizzt32/32/95869_2.png) [@drizzt32](https://forum.freecodecamp.org/u/drizzt32)\
**Post date:** [April 18, 2023, 10:21am UTC](https://forum.freecodecamp.org/t/cant-connect-to-mongodb-with-replit/599536/6 "2023-04-18T10:21:35Z")

</div>

Hi I have same problem. .here are my error message in the replit terminal

```auto
Your app is listening on port 3000
(node:10602) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/
    at NativeConnection.Connection.openUri (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/lib/connection.js:847:32)
    at /home/runner/boilerplate-mongomongoose/node_modules/mongoose/lib/index.js:351:10
    at /home/runner/boilerplate-mongomongoose/node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5
    at new Promise (<anonymous>)
    at promiseOrCallback (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10)
    at Mongoose._promiseOrCallback (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/lib/index.js:1149:10)
    at Mongoose.connect (/home/runner/boilerplate-mongomongoose/node_modules/mongoose/lib/index.js:350:20)
    at Object.<anonymous> (/home/runner/boilerplate-mongomongoose/myApp.js:4:10)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:101:18)
    at Object.<anonymous> (/home/runner/boilerplate-mongomongoose/server.js:67:16)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:10602) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:10602) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

```

---

<div class="post-metadata">

**Author:** ![igorgetmeabrain](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/igorgetmeabrain/32/314517_2.png) [@igorgetmeabrain](https://forum.freecodecamp.org/u/igorgetmeabrain)\
**Post date:** [April 18, 2023, 11:49am UTC](https://forum.freecodecamp.org/t/cant-connect-to-mongodb-with-replit/599536/7 "2023-04-18T11:49:45Z")

</div>

> [@drizzt32](#):
>
> `One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/`

Did you allow access from all IP addresses when you set up your database connection?  
The guide linked in the challenge description explains how to set this up correctly:

> **[MongoDB Atlas Tutorial – How to Get Started](https://www.freecodecamp.org/news/get-started-with-mongodb-atlas/)**
>
> For the following challenges, you are going to use MongoDB to store data. To simplify the configuration, you'll use a service called MongoDB Atlas. Create a MongoDB Atlas Account MongoDB Atlas is a MongoDB Database-as-a-Service platform, which means...

---

<div class="post-metadata">

**Author:** ![drizzt32](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/drizzt32/32/95869_2.png) [@drizzt32](https://forum.freecodecamp.org/u/drizzt32)\
**Post date:** [April 20, 2023, 4:24am UTC](https://forum.freecodecamp.org/t/cant-connect-to-mongodb-with-replit/599536/8 "2023-04-20T04:24:32Z")

</div>

Ahh yes I have done it already and follow the guide. .I switch from replit to glitch and it solve my issues.

---

<div class="post-metadata">

**Author:** ![procord100](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/procord100/32/319848_2.png) [@procord100](https://forum.freecodecamp.org/u/procord100)\
**Post date:** [August 12, 2023, 2:00pm UTC](https://forum.freecodecamp.org/t/cant-connect-to-mongodb-with-replit/599536/9 "2023-08-12T14:00:42Z")

</div>

For those who got the message:

“One common reason is that you’re trying to access the database from an IP that isn’t whitelisted. Make sure your current IP address is on your Atlas cluster’s IP whitelist …”

Please visit your mongoDB homepage, look for “Network Access” in the “SECURITY” section, in the sidebar.

In the “Actions” column, go to “EDIT” and choose “ALLOW ACCESS FROM ANYWHERE”. The status will change to “pending”.  
After the status changes to “active”, you can try to run your code in Replit.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [February 11, 2024, 2:01am UTC](https://forum.freecodecamp.org/t/cant-connect-to-mongodb-with-replit/599536/10 "2024-02-11T02:01:06Z")

</div>

Closed on February 11, 2024, 2:01am UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
