Mongo DB create/save is always timing out

Tell us what’s happening:
When I try to submit my repl link, it says that it timed out. I think i have done everything else right but am currently quite frustrated!

Your code so far
https://repl.it/@SethAlan/boilerplate-mongomongoose-1#myApp.js
you can find my code here, I set up a throwaway user to test it with.

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36.

Challenge: Create and Save a Record of a Model

Link to the challenge:

what link are you submitting?

is your app running when submit? are you looking at the console to see if everything’s alright?

Your code is passing for me when I fork it and add my own .env with a DB connection string.

  1. Make sure you have a .env file and it is using the correct variable name and connection string.

  2. Make sure the project is running before you submit.

  3. Make sure you submit the correct URL, https://boilerplate-mongomongoose-1.sethalan.repl.co

My console spits out the following

(node:3001) UnhandledPromiseRejectionWarning: MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.
    at NativeConnection.Connection.openUri (/home/runner/boilerplate-mongomongoose-1/node_modules/mongoose/lib/connection.js:669:11)
    at /home/runner/boilerplate-mongomongoose-1/node_modules/mongoose/lib/index.js:342:10
    at /home/runner/boilerplate-mongomongoose-1/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:5
    at new Promise (<anonymous>)
    at promiseOrCallback (/home/runner/boilerplate-mongomongoose-1/node_modules/mongoose/lib/helpers/promiseOrCallback.js:30:10)
    at Mongoose.connect (/home/runner/boilerplate-mongomongoose-1/node_modules/mongoose/lib/index.js:341:10)
    at Object.<anonymous> (/home/runner/boilerplate-mongomongoose-1/myApp.js:3:10)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Module.require (internal/modules/cjs/loader.js:1025:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/home/runner/boilerplate-mongomongoose-1/server.js:67:16)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
(node:3001) 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:3001) [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.

I have a .env file, which was just called .env. I made a new one now called env.env (in case it was an issue to have nothing in front of the dot.

it contains the following (not worried about database security here tbh)

MONGO_URI='mongodb+srv://user_repl:replit@cluster0.weri3.mongodb.net/cluster0?retryWrites=true&w=majority'

Odd, it works just fine for me when forking your project and using your connection string.

Try this fork, does it work for you? I will leave it running. and it’s gone.
https://boilerplate-mongomongoose-1.lasjorg.repl.co

Wtf… So somehow that one works. I don’t know why mine isn’t
Thanks a ton!

Hmm, that is really strange, it’s just a fork of your project.

I would suggest you try deleting your .env file and re-make it again. Maybe it got corrupted somehow.

I will try that, hopefully it can work in the next few exercises. Thanks so much for your advice!

Please let us know if you fix it, or run into issue with the next challenge.

I will stop and delete my fork of your project now.

The only way I got it to work was to replace process.env.MONGO_URI with the actual uri, completely circumventing the env file. Even after i made a new file (ensuring there weren’t spaces between the = and everything) it did the same thing. Once i put the URI in app.js it worked fine!

Very strange, thanks for the update.

As long as you have the .env file (named just that, nothing more) it really should work.

I don’t think repl reinstalls packages when you fork something, but just in case, I might try removing the dotenv package and then re-install it, just to test it.

I don’t really know what else to suggest. Other than forking the starter project again, or even forking your own project, just to test a copy.

It would be nice to know why this is happening but I guess it’s not that important as long as you can complete the challenges somehow.