Files

114 lines
3.1 KiB
Markdown
Raw Normal View History

2018-10-12 15:37:13 -04:00
---
title: Install and Set Up Mongoose
---
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
2019-07-24 03:00:45 +10:00
# Install and Set Up Mongoose
2018-10-12 15:37:13 -04:00
---
## Problem Explanation
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.
2018-10-12 15:37:13 -04:00
OR
2018-10-12 15:37:13 -04:00
1. You can use the glitch feature of search packages, install them and update package.json all by itself. (You should use fresh Glitch project from the url given in MongoDb and Mongoose first intro page).
2. Once done add the MONGO_URL in .env file and save your path as
``` mongodb://<dbuser>:<dbpassword>@ds<PORT>.mlab.com:<PORT>/<DATABASE-NAME> ```` which you copy from mLab. Remember to remove the angle brackets ````< >```` when you replace your username and password of your database.
2018-10-12 15:37:13 -04:00
---
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
2019-07-24 03:00:45 +10:00
## Hints
2018-10-12 15:37:13 -04:00
### Hint 1
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
2019-07-24 03:00:45 +10:00
**Timeout error**
2018-10-12 15:37:13 -04:00
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
2019-07-24 03:00:45 +10:00
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 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
2019-07-24 03:00:45 +10:00
**add MONGO_URI to .env**
* Insert a line that looks similar to: `MONGO_URI=mongodb+srv://<username>:<password>@<clustername>-vlas9.mongodb.net/test?retryWrites=true`. `<username>` and `<clustername>` will be automatically generated by MongoDB.
* Replace `<password>` 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.
---
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
2019-07-24 03:00:45 +10:00
## Solutions
<details><summary>Solution 1 (Click to Show/Hide)</summary>
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
2019-07-24 03:00:45 +10:00
**.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://<username>:<ENTERYOURPASSWORDHERE>@<clustername>-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);
```
</details>