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.
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.
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:
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;
(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.
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