Skip to content

Commit bde430c

Browse files
docs: update schema validation and index sections
- Refined instructions for applying and testing schema (users/authors) - Adjusted advanced exercise for authors with TODO methods - Improved validate sections and log explanations - Updated index checking instructions (mongosh / VS Code) - General wording and pattern consistency fixes across docs
1 parent 11668e3 commit bde430c

File tree

8 files changed

+29
-19
lines changed

8 files changed

+29
-19
lines changed

docs/60-schema-validation/2-validate-users.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ The function uses the `db.command()` method to apply the schema to the `users` c
9393
<TabItem value="java" label="☕️ Java Spring Boot">
9494
In this step, we’ll review the code that applies schema validation to the users collection.
9595
It’s already implemented in `SchemaValidationConfig.java` no changes needed. We’ll look at two methods:
96-
```java title='infrastructure/config/SchemaValidationConfig'
96+
```java title='src/main/java/com/mongodb/devrel/library/infrastructure/config/SchemaValidationConfig.java'
9797
@Configuration
9898
public class SchemaValidationConfig {
9999

docs/60-schema-validation/3-validate-authors.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ This is an advanced exercise that requires you to write code. If you get stuck a
2424
<TabItem value="java" label="☕️ Java Spring Boot">
2525
In this advanced exercise, you will extend the [SchemaValidationConfig](https://github.com/mongodb-developer/library-management-system/blob/java-server/java-server/src/main/java/com/mongodb/devrel/library/infrastructure/config/SchemaValidationConfig.java) class to support the authors collection.
2626
Two methods are already defined in the class, but both are left with `// TODO` markers for you to implement:
27-
```java title='../infrastructure/config/SchemaValidationConfig'
27+
```java title='src/main/java/com/mongodb/devrel/library/infrastructure/config/SchemaValidationConfig.java'
2828
private void applyAuthorSchema(MongoDatabase db) {
2929
// TODO: Implement the schema for authors ($jsonSchema with required 'name', 'bio', etc.)
3030
}

docs/70-indexing/1-create-compound-index.mdx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ In this exercise, you will build a compound index following the ESR rule, compar
88

99
## Explore the code
1010

11-
1211
<Tabs groupId="server">
1312
<TabItem value="node" label="🚀 NodeJS/Express">
1413

@@ -82,17 +81,18 @@ In this exercise, you will build a compound index following the ESR rule, compar
8281

8382
<TabItem value="java" label="☕️ Java Spring Boot">
8483

85-
1. Let’s start with our [`java-server/src/main/java/com/mongodb/devrel/library/domain/model/IssueDetail.java`](https://github.com/mongodb-developer/library-management-system/blob/java-server/java-server/src/main/java/com/mongodb/devrel/library/domain/model/IssueDetail.java) record. Right now, it looks like this:
86-
```
84+
1. Let’s start with our [`IssueDetail`](https://github.com/mongodb-developer/library-management-system/blob/java-server/java-server/src/main/java/com/mongodb/devrel/library/domain/model/IssueDetail.java) record. Right now, it looks like this:
85+
```java title='src/main/java/com/mongodb/devrel/library/domain/model/IssueDetail.java'
8786
@Document(collection = "issueDetails")
8887
public record IssueDetail(
8988
// fields ..
9089
) {}
9190
```
9291

93-
2. Now let’s optimize queries that need to filter or sort by multiple fields. For example, we often query by user._id, returnedDate, and borrowDate together.
92+
2. Now let’s optimize queries that need to filter or sort by multiple fields.
93+
For example, we often query by `user._id`, `returnedDate`, and `borrowDate` together.
9494
To speed this up, we can add a compound index using the **@CompoundIndex** annotation.
95-
```java
95+
```java title='src/main/java/com/mongodb/devrel/library/domain/model/IssueDetail.java'
9696
@Document(collection = "issueDetails")
9797
@CompoundIndex(
9898
name = "user_returned_borrow_idx",
@@ -110,7 +110,7 @@ In this exercise, you will build a compound index following the ESR rule, compar
110110
3. Open the `application.yml` and include the property `auto-index-creation: true`. At the end, your configuration will look like this:
111111

112112

113-
```yaml
113+
```yaml title='src/main/resources/application.yml'
114114
spring:
115115
data:
116116
mongodb:
@@ -119,11 +119,11 @@ In this exercise, you will build a compound index following the ESR rule, compar
119119
auto-index-creation: true
120120
```
121121
122-
This ensures that any indexes defined in your domain models (for example with @Indexed) will be created automatically by Spring Data MongoDB at startup.
122+
This ensures that any indexes defined in your domain models (for example, with `@Indexed`) will be created automatically by Spring Data MongoDB at startup.
123123

124124
1. Stop the running app.
125125
1. Locate the bottom panel and click on the `TERMINAL` tab.
126-
1. Press Ctrl+C to interrup the running app
126+
1. Press Ctrl+C/Cmd+c to interrupt the running app
127127

128128
1. Restart the app typing in the Terminal:
129129

@@ -132,15 +132,21 @@ This ensures that any indexes defined in your domain models (for example with @I
132132
```
133133
As soon as the application starts, you will see log entries showing the creation of indexes, similar to the image below.
134134

135-
<Screenshot url="https://github.com/mongodb-developer/library-management-system" src="img/screenshots/70-indexing/index-creation.png" alt="Spring Index creation" />
135+
<Screenshot url="https://github.com/mongodb-developer/library-management-system" src="img/screenshots/70-indexing/1-index-creation.png" alt="Spring Index creation" />
136136

137-
To double-check, you can either open **MongoDB Compass** and inspect the Indexes tab of the issueDetails collection,
138-
or run the following command in mongosh:
137+
To double-check that the index was created, you can run the following command in mongosh:
139138

140139
```
141140
db.issueDetails.getIndexes()
142141
```
143142

143+
:::info
144+
Optional: If you’re using the MongoDB for VS Code extension
145+
, you can also open the issueDetails collection in the VS Code sidebar and inspect the Indexes tab directly.
146+
:::
147+
148+
<Screenshot url="https://github.com/mongodb-developer/library-management-system" src="img/screenshots/70-indexing/2-index-vscode.png" alt="VS Code Playground" />
149+
144150
</TabItem>
145151
</Tabs>
146152

docs/75-optimize/2-patterns.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ At this point, we also have to do additional queries to display the first five r
7777
Let's look at the current code that is used to retrieve a single book.
7878
Open the [`BookService`](https://github.com/mongodb-developer/library-management-system/blob/java-server/java-server/src/main/java/com/mongodb/devrel/library/domain/service/BookService.java) class and check the `getBook` method:
7979

80-
```java
80+
```java title='src/main/java/com/mongodb/devrel/library/domain/service/BookService.java'
8181
public Optional<Book> getBook(String id) {
8282
Aggregation aggregation = Aggregation.newAggregation(
8383
Aggregation.match(Criteria.where("_id").is(id)),
@@ -106,9 +106,9 @@ Open the [`BookService`](https://github.com/mongodb-developer/library-management
106106
107107
```
108108

109-
This method is doing the same steps as the Node.js code:
109+
The method does the following:
110110

111-
1. **Aggregation.match**: filters the book by _id (just like a SQL WHERE).
111+
1. **Aggregation.match**: filters the book by `_id` (just like a `SQL WHERE`).
112112

113113
2. **LookupOperation.newLookup()**: performs a join with the issueDetails collection to get related records.
114114
- Here we filter only reservations or borrowed books that havent been returned yet.
@@ -117,7 +117,7 @@ This method is doing the same steps as the Node.js code:
117117
3. **Aggregation.addFields()**: computes the available field by subtracting issued books from the total inventory.
118118
4. **Aggregation.project()**: removes the temporary details field before returning the final result.
119119

120-
Just like in Node.js, this approach works but its not efficientit simulates a relational-style query in MongoDB.
120+
This approach works, but its not efficientit simulates a relational-style query in MongoDB.
121121
We will later see how to apply patterns to improve this.
122122
</TabItem>
123123
</Tabs>

docs/75-optimize/3-optimize.mdx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,17 @@ How many calls do you need to do to your database now? Do you still need an aggr
3434
</TabItem>
3535

3636
<TabItem value="java" label="☕️ Java Spring Boot">
37-
Open the BookService class, and look for the getBook method. How could you simplify this code to make it blazing fast, using the patterns we just discussed?
37+
1. Open the `BookService` class
38+
39+
2. locate the `getBook` method.
40+
41+
How could you simplify this code to make it blazing fast, using the patterns we just discussed?
3842

3943
<details>
4044
<summary>Click here to see the answer</summary>
4145

4246
<div>
43-
```java
47+
```java title='src/main/java/com/mongodb/devrel/library/domain/service/BookService.java'
4448
public Optional<Book> getBook(String id) {
4549
return bookRepository.findById(id);
4650
}
810 KB
Loading
485 KB
Loading
-201 KB
Binary file not shown.

0 commit comments

Comments
 (0)