URL Shortener Microservice Help Getting Started


It’s been a very long time since I have dove back into FCC after things getting busy. Now that I have a lot of time on my hands, I am looking to finish these projects.

One small problem. I have forgotten how to get the ball rolling here and get this project hooked up to the database and forgotten how to do the project after getting the first two done without problems.

Any assistance, help, guidance would be greatly appreciated. Thanks.

1 Like

Hi six03, still stuck?

  • Did you already start your glitch project?

  • Since the glitch base project url comes almost empty (no files or starting boilerplate), I suggest you to import the github repository of the challenge into your glitch project

  • After that is done, you should create a new .env file into the root of the glitch project, so you can save the mongodb url you are going to create at the mongodb atlas site later.

But first let me know if you handled correctly these first 3 things.


1 Like

Hi @Pedroomedicinaa,

Thanks for answering, sorry it has taken me this long to respond.

I have the glitch project set up, yes. *** Restarting Project will provide URL later***

I also have imported the GitHub repo into the project as well.

I will create the new .env file and keep watch on this thread so I can respond quicker. Thank you!

1 Like

Don’t worry, it’s a forum not a chat hehe…

nice there, then:

  • Sign in/sign up into mongodb .com
  • Create a cluster (and a user that can connect to that cluster, be sure you save the password somewhere safe)
  • Whitelist IP address to allow access from anywhere (this is required for fcc tests as far as I know)
  • When all that is done click on connect to cluster, click on “connect your application” and take the connection uri that is displayed.
  • Put that connection string into de .env file you created on the root of your glitch project, your env should look like:


Another thing you should change in the string is the db name it is connecting to, you can do so by changing the “test” word for a more appropiate word like “uri-shortener” or whatever fits for you.

There is a video tutorial from mongodb channel youtube entitled “Getting Your Free MongoDB Atlas Cluster” published 7 months ago. (sorry can’t post external urls)

  • In the video, the guy only whitelists it´s own ip address, make youre you whitelist all of em.
  • The guy takes a connection string to use with compass, make sure you use an appropiated one for applications, (I guess is shorter and with less query params).

After you created a cluster and pasted the url in the .env file, the last step to get your db hooked is to uncomment the line in server.js file of your glitch project that reads:

// mongoose.connect(process.env.DB_URI);

let me know if you could handle this.


The only URL is see is like this;




I don’t see anything with DB_URI= in front of it. I guess this is where lies confusion on my end.

1 Like

See a good progress,

two last steps:

  • open .env file and paste the following:

then proceed to uncomment the line on server.js file that reads:

// mongoose.connect(process.env.DB_URI);

It is important that you write DB_URI as a variable name in your .env file, since we are using process.env.DB_URI in the mongoose.connect(…) expression; you can obviously change it to i.e. MONGO_URI, but make sure the variable name is in both places;

I finally got those steps down https://glitch.com/edit/#!/elite-arrow-condor

Now to find out why these errors are appearing;

(node:2674) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: bad auth Authentication failed.

    at new MongooseServerSelectionError (/rbd/pnpm-volume/36ff1831-db27-4271-9e91-f1ee28b29d70/node_modules/.registry.npmjs.org/mongoose/5.9.9/node_modules/mongoose/lib/error/serverSelection.js:22:11)

    at NativeConnection.Connection.openUri (/rbd/pnpm-volume/36ff1831-db27-4271-9e91-f1ee28b29d70/node_modules/.registry.npmjs.org/mongoose/5.9.9/node_modules/mongoose/lib/connection.js:823:32)

    at Mongoose.connect (/rbd/pnpm-volume/36ff1831-db27-4271-9e91-f1ee28b29d70/node_modules/.registry.npmjs.org/mongoose/5.9.9/node_modules/mongoose/lib/index.js:333:15)

at Object.<anonymous> (/app/server.js:15:10)

    at Module._compile (internal/modules/cjs/loader.js:701:30)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)

    at Module.load (internal/modules/cjs/loader.js:600:32)

    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)

    at Function.Module._load (internal/modules/cjs/loader.js:531:3)

    at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)

    at startup (internal/bootstrap/node.js:283:19)

    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

(node:2674) 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(). (rejection id: 1)

(node:2674) [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.

Seems like your mongodb cluster user credentials in the connection string are wrong.

  1. Sign in in mongodb .com
  2. Search for ‘Database Access’ in the left pannel, click on it.
  3. Edit/Create a database user, with “read/write to any database” permission
  4. Take username and password of that user and put them in the connection string you are using in the .env file


change <mongo_cluster_user> for username and <mongo_cluster_user_password> for password.

If you selected six03 as username and 123qwer as password it should read now as:


cheers, you are so close!

1 Like

I’ll hit that tomorrow and let you know how it goes. Thanks!

1 Like

I wasn’t able to get to this but I am today. No errors, and I have totally forgotten where to start. So the connection to the db is good. Thanks for the help @Pedroomedicinaa

1 Like