From 7f3769f8e04421a55e8ecefab17cfec7be3805d8 Mon Sep 17 00:00:00 2001 From: Ai-Lyn Tang Date: Wed, 24 Jul 2019 03:00:45 +1000 Subject: [PATCH] Add hints for "install and set up mongoose" (#36474) * Add hints for "install and set up mongoose" * Add hint for how to solve the timeout error * Add hint for what to put in the `.env` file * Add code snippets for `.env`, `package.json` and `myApp.js` * Restructure hints and headers * Remove code solution from timeout hint * Restructure headers to match the new hint template * Move hint subject below the header Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * Move hint subject below the header Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * Update text in spoiler tag Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * Update text in spoiler tag Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * Update text in spoiler tag Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * Add javascript tag to code block Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * Move first line of code below ``` Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * Remove placeholder text Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * Add json tag to code block Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * Remove redundant sentence Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * Format solutions section and hint * Replace tabs with 2 space indents in `package.json` * Remove the spoiler tags from each file name * Remove placeholder comments in `myApp.js` to make it easier to read the code * Update sentence in hint as two words were not displaying --- .../install-and-set-up-mongoose/index.md | 94 ++++++++++++++++++- 1 file changed, 92 insertions(+), 2 deletions(-) diff --git a/guide/english/certifications/apis-and-microservices/mongodb-and-mongoose/install-and-set-up-mongoose/index.md b/guide/english/certifications/apis-and-microservices/mongodb-and-mongoose/install-and-set-up-mongoose/index.md index 0108ba03fe..4d014daef5 100644 --- a/guide/english/certifications/apis-and-microservices/mongodb-and-mongoose/install-and-set-up-mongoose/index.md +++ b/guide/english/certifications/apis-and-microservices/mongodb-and-mongoose/install-and-set-up-mongoose/index.md @@ -1,7 +1,7 @@ --- title: Install and Set Up Mongoose --- -## Install and Set Up Mongoose +# Install and Set Up Mongoose You might want to check both the [MongoDB](https://www.npmjs.com/package/mongodb) and the [Mongoose](https://www.npmjs.com/package/mongoose) NPM Repositories for the manual configuration if you are not using Giltch. @@ -12,6 +12,96 @@ OR 2. Once done add the MONGO_URL in .env file and save your path as ```` mongodb://:@ds.mlab.com:/ ```` which you copy from mLab. Remember to remove the angle brackets ````< >```` when you replace your username and password of your database. +## Hints + +### Hint #1 +**Timeout error** + +If the tests are timing out, check the `package.json` file. Ensure the final dependency does not end in a `,`. + +For example, this will result in a timeout error: +``` +"dependencies": { + "express": "^4.12.4", + "body-parser": "^1.15.2", +}, +``` + +### Hint #2 +**add MONGO_URI to .env** +* Insert a line that looks similar to: `MONGO_URI=mongodb+srv://:@-vlas9.mongodb.net/test?retryWrites=true`. `` and `` will be automatically generated by MongoDB. + +* Replace `` with your password. There should be no `<>` characters (unless those are in your password). + +Still having issues? Check the below hints: + +* Remove spaces before and after `=`. This is correct: `MONGO_URI=mongodb...`. This is incorrect: `MONGO_URI = mongodb...` + +* Do you have symbols or special characters in your password, e.g. `$&(@`? If so, you will need to translate these into unicode. MongoDB has instructions on how to do this. I would suggest changing your password to be lettes and numbers only for simplicity. - +## Solutions + +
Solution #1 (Click to Show/Hide) + +**.env** + +``` +GLITCH_DEBUGGER=true +# Environment Config + +# store your secrets and config variables in here +# only invited collaborators will be able to see your .env values + +# reference these in your code with process.env.SECRET +SECRET= +MADE_WITH= +MONGO_URI=mongodb+srv://:@-vlas9.mongodb.net/test?retryWrites=true +# note: .env is a shell file so there can't be spaces around = +``` + +**package.json** + +```json +{ + "name": "fcc-mongo-mongoose-challenges", + "version": "0.0.1", + "description": "A boilerplate project", + "main": "server.js", + "scripts": { + "start": "node server.js" + }, + "dependencies": { + "express": "^4.12.4", + "body-parser": "^1.15.2", + "mongodb": "^3.0.0", + "mongoose": "^5.6.5" + }, + "engines": { + "node": "4.4.5" + }, + "repository": { + "type": "git", + "url": "https://hyperdev.com/#!/project/welcome-project" + }, + "keywords": [ + "node", + "hyperdev", + "express" + ], + "license": "MIT" +} +``` + +**myApp.js** + +```javascript +/** # MONGOOSE SETUP # +/* ================== */ + +/** 1) Install & Set up mongoose */ +const mongoose = require('mongoose'); +mongoose.connect(process.env.MONGO_URI); +``` +
+