You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
218
218
219
219
```js
220
220
constbcrypt=require('bcrypt')
@@ -455,7 +455,7 @@ const noteSchema = new mongoose.Schema({
455
455
})
456
456
```
457
457
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:
459
459
460
460
```js
461
461
constuser=awaitUser.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
486
486
487
487
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.
488
488
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:
@@ -503,7 +503,7 @@ The result is almost exactly what we wanted:
503
503
504
504

505
505
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>.
507
507
508
508
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):
509
509
@@ -520,7 +520,7 @@ The result is now exactly like we want it to be:
520
520
521
521

522
522
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:
@@ -535,7 +535,7 @@ Now the user's information is added to the <i>user</i> field of note objects.
535
535
536
536

537
537
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.
539
539
540
540
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:
0 commit comments