Skip to content

Commit 6d9c22f

Browse files
authored
Merge pull request #3537 from FiggyHunter/patch-2
Update part4c.md
2 parents 36775fc + 7166cad commit 6d9c22f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/content/4/en/part4c.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ const userSchema = mongoose.Schema({
370370
// ...
371371
```
372372

373-
However, care must be taken with the uniqueness index. If there are already documents in the database that violate the uniqueness condition, [no index will be created](https://dev.to/akshatsinghania/mongoose-unique-not-working-16bf). So when adding a uniqueness index, make sure that the database is in a healthy state! The test above added the user with username _root_ to the database twice, and these must be removed for the index to be formed and the code to work.
373+
However, we want to be careful when using the uniqueness index. If there are already documents in the database that violate the uniqueness condition, [no index will be created](https://dev.to/akshatsinghania/mongoose-unique-not-working-16bf). So when adding a uniqueness index, make sure that the database is in a healthy state! The test above added the user with username _root_ to the database twice, and these must be removed for the index to be formed and the code to work.
374374

375375
Mongoose validations do not detect the index violation, and instead of _ValidationError_ they return an error of type _MongoServerError_. We therefore need to extend the error handler for that case:
376376

0 commit comments

Comments
 (0)