Skip to content

Commit b96a0cd

Browse files
author
Sam Vitare
authored
Update part4c.md
Some more clarity added and grammar.
1 parent 8301b27 commit b96a0cd

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/content/4/en/part4c.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ const usersRouter = require('./controllers/users')
214214
app.use('/api/users', usersRouter)
215215
```
216216

217-
The contents of the file, <i>controllers/users.js</i>, that defines the router are as follows:
217+
The contents of the file, <i>controllers/users.js</i>, that defines the router is as follows:
218218

219219
```js
220220
const bcrypt = require('bcrypt')
@@ -455,7 +455,7 @@ const noteSchema = new mongoose.Schema({
455455
})
456456
```
457457

458-
It's worth noting that the <i>user</i> object also changes. The <i>id</i> of the note is stored in the <i>notes</i> field:
458+
It's worth noting that the <i>user</i> object also changes. The <i>id</i> of the note is stored in the <i>notes</i> field of the <i>user</i> object:
459459

460460
```js
461461
const user = await User.findById(body.userId)
@@ -486,7 +486,7 @@ We would like our API to work in such a way, that when an HTTP GET request is ma
486486

487487
As previously mentioned, document databases do not properly support join queries between collections, but the Mongoose library can do some of these joins for us. Mongoose accomplishes the join by doing multiple queries, which is different from join queries in relational databases which are <i>transactional</i>, meaning that the state of the database does not change during the time that the query is made. With join queries in Mongoose, nothing can guarantee that the state between the collections being joined is consistent, meaning that if we make a query that joins the user and notes collections, the state of the collections may change during the query.
488488

489-
The Mongoose join is done with the [populate](http://mongoosejs.com/docs/populate.html) method. Let's update the route that returns all users first in <i>controllers/users.js</i>:
489+
The Mongoose join is done with the [populate](http://mongoosejs.com/docs/populate.html) method. Let's update the route that returns all users first in <i>controllers/users.js</i> file:
490490

491491
```js
492492
usersRouter.get('/', async (request, response) => {
@@ -503,7 +503,7 @@ The result is almost exactly what we wanted:
503503

504504
![JSON data showing populated notes and users data with repetition](../../images/4/13new.png)
505505

506-
We can use the populate parameter for choosing the fields we want to include from the documents. In addition to the field id:n we are now only interested in <i>content</i> and <i>important</i>.
506+
We can use the populate parameter for choosing the fields we want to include from the documents. In addition to the field <i>id</i> we are now only interested in <i>content</i> and <i>important</i>.
507507

508508
The selection of fields is done with the Mongo [syntax](https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/#return-the-specified-fields-and-the-id-field-only):
509509

@@ -520,7 +520,7 @@ The result is now exactly like we want it to be:
520520

521521
![combined data showing no repetition](../../images/4/14new.png)
522522

523-
Let's also add a suitable population of user information to notes in <i>controllers/notes.js</i>:
523+
Let's also add a suitable population of user information to notes in the <i>controllers/notes.js</i> file:
524524

525525
```js
526526
notesRouter.get('/', async (request, response) => {
@@ -535,7 +535,7 @@ Now the user's information is added to the <i>user</i> field of note objects.
535535

536536
![notes JSON now has user info embedded too](../../images/4/15new.png)
537537

538-
It's important to understand that the database does not know that the ids stored in the <i>user</i> field of notes reference documents in the user collection.
538+
It's important to understand that the database does not know that the ids stored in the <i>user</i> field of the notes collection reference documents in the user collection.
539539

540540
The functionality of the <i>populate</i> method of Mongoose is based on the fact that we have defined "types" to the references in the Mongoose schema with the <i>ref</i> option:
541541

0 commit comments

Comments
 (0)