Skip to content

Commit 4111e8b

Browse files
authored
Merge pull request #3954 from sudo-rickroll/patch-8
Update part4c.md
2 parents e9d533a + c75bb79 commit 4111e8b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/content/4/en/part4c.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ The ids of the notes are stored within the user document as an array of Mongo id
169169
}
170170
```
171171

172-
The type of the field is <i>ObjectId</i> that references <i>note</i>-style documents. Mongo does not inherently know that this is a field that references notes, the syntax is purely related to and defined by Mongoose.
172+
The type of the field is <i>ObjectId</i> that references <i>note</i>-style documents. Mongo does not inherently know that this is a field that references notes, the syntax is purely related to and defined by Mongoose. The <i>ref</i> field suggests the name of the model that will be referred to.
173173

174174
Let's expand the schema of the note defined in the <i>models/note.js</i> file so that the note contains information about the user who created it:
175175

@@ -500,7 +500,7 @@ usersRouter.get('/', async (request, response) => {
500500
})
501501
```
502502

503-
The [populate](http://mongoosejs.com/docs/populate.html) method is chained after the <i>find</i> method making the initial query. The argument given to the populate method defines that the <i>ids</i> referencing <i>note</i> objects in the <i>notes</i> field of the <i>user</i> document will be replaced by the referenced <i>note</i> documents.
503+
The [populate](http://mongoosejs.com/docs/populate.html) method is chained after the <i>find</i> method making the initial query. The argument given to the populate method defines that the <i>ids</i> referencing <i>note</i> objects in the <i>notes</i> field of the <i>user</i> document will be replaced by the referenced <i>note</i> documents. Mongoose first queries the <i>users</i> collection for the list of users, and then queries the collection corresponding to the model object specified by the <i>ref</i> property in the users schema for data with the given object id.
504504

505505
The result is almost exactly what we wanted:
506506

0 commit comments

Comments
 (0)