Skip to content

[PR] Merge master branch into start branch #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,9 @@
* [mLab](https://mlab.com/)

## Course
Thanks for taking the Intro to MongoDB course, created by Scott Moss & Frontend Masters. This course aims to cover a wide intro into using MongoDb with Nodejs. Topics refrain from going deep, but instead, focus on a wide view.
## Excercises
Note: To handle the error "MongoError: E11000 duplicate key error collection" by dropping the database
```bash
mongo
use dbName;
db.dropDatabase();
exit
```
(dbName is the name of the database)
Thanks for taking the [Introduction to MongoDB course](https://frontendmasters.com/courses/mongodb/), created by Scott Moss & Frontend Masters. This course aims to cover a wide intro into using MongoDb with Nodejs. Topics refrain from going deep, but instead, focus on a wide view.

## Exercises

### Installing MongoDB
There are many ways to install MongoDB. [The offical website](https://www.mongodb.com/download-center#community) has you covered either way. After installation, you might have to add a `dbPath`, a location where mongodb saves your data. You can do so like this.
Expand All @@ -35,9 +28,10 @@ mkdir -p /data/db
```
Note: If you have an error like "data directory not found" or "permission denied" while installing MongoDB:
```bash
sudo mkdir /data/db
sudo mkdir -p /data/db
sudo chown -R $USER /data/db
```

### Models
* location - `exercises/models`
* commands
Expand All @@ -51,6 +45,7 @@ This exercise will have you create connection logic and mongoose schemas. Using
- [ ] create connection logic on `connect.js`
- [ ] finish the user schema so that the the user model tests pass
- [ ] complete the crud functions with the user model and get all the crud test to pass

### Queries
* location - `exercises/queries`
* commands
Expand All @@ -64,6 +59,7 @@ This exercise will have you add relationships between models. You'll then use th
- [ ] the post model should have a one-to-many similarPost field that points to posts
- [ ] get all the post model tests to pass
- [ ] get all the query tests to pass

### Hooks
* location - `exercises/hooks`
* commands
Expand All @@ -79,6 +75,7 @@ In this exercise, you'll learn how to use schema middleware and virtuals. Also,
- [ ] add a virtual getter to the org schema called `avatar` that creates the fill url to the org avatar by concatinating the cdnUrl with the org id
- [ ] get all org tests to pass
- [ ] get all project tests to pass

### App
* location - `exercises/app`
* commands
Expand All @@ -93,4 +90,14 @@ In this exercise, you'll have to create queries in Expressjs controllers to sati
- [ ] create db mutation for `POST /todo/`
- [ ] **optional** create a mLab sandbox and use your hosted DB

## Debugging
Note: To handle the error `MongoError: E11000 duplicate key error collection` drop the database.

```bash
mongo
use dbName;
db.dropDatabase();
exit
```

(dbName is the name of the database)
28 changes: 14 additions & 14 deletions exercises/queries/__test__/queries.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {
const Post = require('../post')
const Author = require('../author')
const mongoose = require('mongoose')
const createConent = (length, fill = 'b') => new Array(length).fill(fill).join('')
const createContent = (length, fill = 'b') => new Array(length).fill(fill).join('')

describe('queries', () => {
describe('postByTitle', () => {
Expand All @@ -18,7 +18,7 @@ describe('queries', () => {
const post = await Post.create({
title,
author: mongoose.Types.ObjectId(),
content: createConent(50),
content: createContent(50),
contentLength: 50
})

Expand All @@ -33,7 +33,7 @@ describe('queries', () => {
const post = await Post.create({
author,
title: 'Carter v',
content: createConent(50),
content: createContent(50),
contentLength: 50
})
const [match] = await postsForAuthor(author)
Expand All @@ -46,9 +46,9 @@ describe('queries', () => {
const author = mongoose.Types.ObjectId()

const posts = await Post.create([
{title: 'Super Duper', author, content: createConent(1000), contentLength: 1000},
{title: 'Amazing', author, content: createConent(100), contentLength: 100},
{title: 'Other', author, content: createConent(800), contentLength: 800}
{title: 'Super Duper', author, content: createContent(1000), contentLength: 1000},
{title: 'Amazing', author, content: createContent(100), contentLength: 100},
{title: 'Other', author, content: createContent(800), contentLength: 800}
])

const matches = await postByContentLength(1000, 100)
Expand All @@ -64,15 +64,15 @@ describe('queries', () => {
const post = await Post.create({
title: 'Super Duper',
author: author.id,
content: createConent(1000),
content: createContent(1000),
contentLength: 1000
})
const post2 = await Post.create({
author: author.id,
title: 'Post 2',
content: createConent(100),
content: createContent(100),
contentLength: 100,
simularPosts: [post.id]
similarPosts: [post.id]
})

const match = await fullPostById(post2.id)
Expand All @@ -83,9 +83,9 @@ describe('queries', () => {
test('only selects fields given', async () => {
const author = mongoose.Types.ObjectId()
await Post.create([
{title: 'learn things', content: createConent(100), contentLength: 100, author},
{title: 'lean more things', content: createConent(100), contentLength: 100, author},
{title: 'lean more things++', content: createConent(100), contentLength: 100, author}
{title: 'learn things', content: createContent(100), contentLength: 100, author},
{title: 'lean more things', content: createContent(100), contentLength: 100, author},
{title: 'lean more things++', content: createContent(100), contentLength: 100, author}
])

const matches = await allPostsSlim({title: 1, content: 1})
Expand All @@ -98,12 +98,12 @@ describe('queries', () => {
})
})
describe('addRelatedPosts', () => {
test('should not overrided related posts that are there', async () => {
test('should not override related posts that are there', async () => {
const author = mongoose.Types.ObjectId()
const post = await Post.create({
author,
title: 'Post',
content: createConent(100),
content: createContent(100),
contentLength: 100,
similarPosts: [mongoose.Types.ObjectId()]
})
Expand Down
2 changes: 1 addition & 1 deletion exercises/queries/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const postSchema = new mongoose.Schema({
},
isFeatured: {
type: Boolean,
deafult: false
default: false
}
}, {timestamps: true})

Expand Down