Skip to content

Commit 8494193

Browse files
committed
mongoose uniq validator heads up
1 parent efd335f commit 8494193

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/content/4/en/part4c.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,18 @@ userSchema.plugin(uniqueValidator) // highlight-line
379379
// ...
380380
```
381381

382+
Note: when installing the _mongoose-unique-validator_ library, you may encounter the following error message:
383+
384+
![](../../images/4/uniq.png)
385+
386+
The reason for this is that the library is not yet compatible with Mongoose version 7 at the time of writing (March 13, 2023). If you encounter an error, you can downgrade to an older version of Mongoose by running the command
387+
388+
```
389+
npm install mongoose@6
390+
```
391+
392+
After this, you can install the library _mongoose-unique-validator_ without problems.
393+
382394
We could also implement other validations into the user creation. We could check that the username is long enough, that the username only consists of permitted characters, or that the password is strong enough. Implementing these functionalities is left as an optional exercise.
383395

384396
Before we move onward, let's add an initial implementation of a route handler that returns all of the users in the database:

src/content/4/fi/osa4c.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,18 @@ userSchema.plugin(uniqueValidator) // highlight-line
380380
// ...
381381
```
382382

383+
Huom: asentaessasi kirjastoa _mongoose-unique-validator_ saatat törmätä seuraavaan virheilmoitukseen:
384+
385+
![](../../images/4/uniq.png)
386+
387+
Syynä tälle on se, että kirjasto ei ole kirjoitushetkellä (13.3.2023) vielä yhteensopiva Mongoosen version 7 kanssa. Jos törmäät virheeseen, voit ottaa käyttöösi Mongoosen vanhemman version suorittamalla komennon
388+
389+
```
390+
npm install mongoose@6
391+
```
392+
393+
Tämän jälkeen kirjaston _mongoose-unique-validator_ asentaminen onnistuu.
394+
383395
Voisimme toteuttaa käyttäjien luomisen yhteyteen myös muita tarkistuksia, esim. onko käyttäjätunnus tarpeeksi pitkä, koostuuko se sallituista merkeistä ja onko salasana tarpeeksi hyvä. Jätämme ne kuitenkin vapaaehtoiseksi harjoitustehtäväksi.
384396

385397
Ennen kuin menemme eteenpäin, lisätään sovellukseen alustava versio kaikki käyttäjät palauttavasta käsittelijäfunktiosta:

src/content/images/4/uniq.png

77.6 KB
Loading

0 commit comments

Comments
 (0)