Skip to content

Commit 01519bf

Browse files
committed
Update mongoDB instructions and pictures in part 3
1 parent 2b0d1de commit 01519bf

File tree

10 files changed

+21
-29
lines changed

10 files changed

+21
-29
lines changed

src/content/3/en/part3c.md

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,11 @@ Read now the chapters on [collections](https://docs.mongodb.com/manual/core/data
7777

7878
Naturally, you can install and run MongoDB on your computer. However, the internet is also full of Mongo database services that you can use. Our preferred MongoDB provider in this course will be [MongoDB Atlas](https://www.mongodb.com/atlas/database).
7979

80-
Once you've created and logged into your account, let us start by selecting the free option:
81-
82-
![mongodb deploy a cloud database free shared](../../images/3/mongo1.png)
83-
84-
Pick the cloud provider and location and create the cluster:
80+
Once you've created and logged into your account, let's create a new cluster using the button visible on the front page. From the view that opens, select the free plan, determine the cloud provider and data center, and create the cluster:
8581

8682
![mongodb picking shared, aws and region](../../images/3/mongo2.png)
8783

88-
Let's wait for the cluster to be ready for use. This can take some minutes.
84+
The provider selected is <i>AWS</i> and the region is <i>Stockholm (eu-north-1)</i>. Note that if you choose something else, your database connection string will be slightly different from this example. Wait for the cluster to be ready, which will take a few minutes.
8985

9086
**NB** do not continue before the cluster is ready.
9187

@@ -98,19 +94,19 @@ Next, we have to define the IP addresses that are allowed access to the database
9894
![mongodb network access/add ip access list](../../images/3/mongo4.png)
9995

10096
Note: In case the modal menu is different for you, according to MongoDB documentation, adding 0.0.0.0 as an IP allows access from anywhere as well.
101-
102-
Finally, we are ready to connect to our database. To do this, we need the database connection string, which can be found by first clicking <i>connect</i> and then choosing <i>Connect to your application</i>:
97+
98+
Finally, we are ready to connect to our database. To do this, we need the database connection string, which can be found by selecting <i>Connect</i> and then <i>Drivers</i> from the view, under the <i>Connect to your application</i> section:
10399

104100
![mongodb database deployment connect](../../images/3/mongo5.png)
105101

106102
The view displays the <i>MongoDB URI</i>, which is the address of the database that we will supply to the MongoDB client library we will add to our application:
107103

108-
![mongodb connect application](../../images/3/mongo6.png)
104+
![mongodb connect application](../../images/3/mongo6new.png)
109105

110106
The address looks like this:
111107

112108
```js
113-
mongodb+srv://fullstack:[email protected]/?retryWrites=true&w=majority
109+
mongodb+srv://fullstack:[email protected]/?retryWrites=true&w=majority&appName=Cluster0
114110
```
115111

116112
We are now ready to use the database.
@@ -138,7 +134,7 @@ if (process.argv.length<3) {
138134
const password = process.argv[2]
139135

140136
const url =
141-
`mongodb+srv://fullstack:${password}@cluster0.a5qfl.mongodb.net/?retryWrites=true&w=majority`
137+
`mongodb+srv://fullstack:${password}@cluster0.a5qfl.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0`
142138

143139
mongoose.set('strictQuery',false)
144140

@@ -186,7 +182,7 @@ Let's destroy the default database <i>test</i> and change the name of the databa
186182

187183
```js
188184
const url =
189-
`mongodb+srv://fullstack:${password}@cluster0.a5qfl.mongodb.net/noteApp?retryWrites=true&w=majority`
185+
`mongodb+srv://fullstack:${password}@cluster0.a5qfl.mongodb.net/noteApp?retryWrites=true&w=majority&appName=Cluster0`
190186
```
191187

192188
Let's run our code again:
@@ -368,7 +364,7 @@ const password = process.argv[2]
368364

369365
// DO NOT SAVE YOUR PASSWORD TO GITHUB!!
370366
const url =
371-
`mongodb+srv://fullstack:${password}@cluster0.a5qfl.mongodb.net/?retryWrites=true&w=majority`
367+
`mongodb+srv://fullstack:${password}@cluster0.a5qfl.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0`
372368

373369
mongoose.set('strictQuery',false)
374370
mongoose.connect(url)
@@ -384,7 +380,7 @@ const Note = mongoose.model('Note', noteSchema)
384380
To avoid authentication issues with the password variable in index.js, we need to create a .env file by running npm install dotenv in the command line. Then, let's create the .env file in the root of your directory. In that file, you should place your URI:
385381

386382
```
387-
MONGODB_URI="mongodb+srv://fullstack:[email protected].mongodb.net/?retryWrites=true&w=majority&appName=db"
383+
MONGODB_URI="mongodb+srv://fullstack:[email protected].mongodb.net/?retryWrites=true&w=majority&appName=Cluster0"
388384
```
389385
Don't forget to replace the string with your details.
390386
Once the .env file is ready, remember to add it to your .gitignore file to prevent pushing the password to Git:
@@ -536,7 +532,7 @@ npm install dotenv
536532
To use the library, we create a <i>.env</i> file at the root of the project. The environment variables are defined inside of the file, and it can look like this:
537533

538534
```bash
539-
MONGODB_URI=mongodb+srv://fullstack:[email protected]/noteApp?retryWrites=true&w=majority
535+
MONGODB_URI=mongodb+srv://fullstack:[email protected]/noteApp?retryWrites=true&w=majority&appName=Cluster0
540536
PORT=3001
541537
```
542538

@@ -579,7 +575,7 @@ However, a [better option](https://community.fly.io/t/clarification-on-environme
579575
and set the env value from the command line with the command:
580576

581577
```bash
582-
fly secrets set MONGODB_URI="mongodb+srv://fullstack:[email protected]/noteApp?retryWrites=true&w=majority"
578+
fly secrets set MONGODB_URI="mongodb+srv://fullstack:[email protected]/noteApp?retryWrites=true&w=majority&appName=Cluster0"
583579
```
584580

585581
Since the PORT also is defined in our .env it is actually essential to ignore the file in Fly.io since otherwise the app starts in the wrong port.

src/content/3/fi/osa3c.md

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,11 @@ Lue nyt linkitetty [johdanto](https://github.com/fullstack-hy2020/misc/blob/mast
7777

7878
MongoDB:n voi asentaa paikallisesti omalle koneelle. Internetistä löytyy kuitenkin myös palveluna toimivia Mongoja, joista tämän hetken paras valinta on [MongoDB Atlas](https://www.mongodb.com/atlas/database).
7979

80-
Kun käyttäjätili on luotu ja kirjauduttu, Aloitetaan valitsemalla kokeiluihin sopiva ilmainen vaihtoehto
81-
82-
![Valitaan 'shared', joka on ilmainen](../../images/3/mongo1.png)
83-
84-
Valitaan sopiva pilvipalvelu ja konesali, ja luodaan klusteri:
80+
Kun käyttäjätili on luotu ja kirjauduttu, luodaan käyttöömme uusi klusteri etusivulla näkyvästä painikkeesta. Avautuvasta näkymästä valitaan kokeiluihin sopiva ilmainen vaihtoehto sekä pilvipalvelu ja konesali, ja luodaan klusteri:
8581

8682
![Valitaan esim AWS Stockholm ja klikataan Create cluster](../../images/3/mongo2.png)
8783

88-
Odotetaan että klusteri on valmiina, mihin menee noin useita minuutteja.
84+
Provideriksi on valittu _AWS_ ja Regioniksi _Stockholm (eu-north-1)_. Huomaa, että jos valitset näihin jotakin muuta, tulee tietokannan yhteysosoitteesi olemaan hieman erilainen kuin tässä esimerkissä. Odotetaan että klusteri on valmiina, mihin menee joitakin minuutteja.
8985

9086
**HUOM:** Älä jatka eteenpäin ennen kun klusteri on valmis!
9187

@@ -97,7 +93,7 @@ Seuraavaksi tulee määritellä ne IP-osoitteet, joista tietokantaan pääsee k
9793

9894
![Valitaan Network access ‑välilehdeltä 'Allow access from anywhere'](../../images/3/mongo4.png)
9995

100-
Lopulta ollaan valmiina ottamaan tietokantayhteys. Yhteyden muodostamiseksi tarvitsemme tietokannan yhteysosoitteen, joka löytyy esimerkiksi valitsemalla <i>connect</i> ja sen jälkeisestä näkymästä <i>connect your application</i>:
96+
Lopulta ollaan valmiina ottamaan tietokantayhteys. Yhteyden muodostamiseksi tarvitaan tietokannan yhteysosoite, joka löytyy esimerkiksi valitsemalla <i>connect</i> ja sen jälkeisestä näkymästä <i>Connect your application</i>-osiosta kohta <i>Drivers</i>:
10197

10298
![Valitaan Databases-välilehdeltä 'Connect'](../../images/3/mongo5.png)
10399

@@ -108,7 +104,7 @@ Näkymä kertoo <i>MongoDB URI:n</i> eli osoitteen, jonka avulla sovelluksemme k
108104
Osoite näyttää seuraavalta:
109105

110106
```bash
111-
mongodb+srv://fullstack:[email protected]/?retryWrites=true&w=majority
107+
mongodb+srv://fullstack:[email protected]/?retryWrites=true&w=majority&appName=Cluster0
112108
```
113109

114110
Olemme nyt valmiina kannan käyttöön.
@@ -136,7 +132,7 @@ if (process.argv.length<3) {
136132
const password = process.argv[2]
137133

138134
const url =
139-
`mongodb+srv://fullstack:${password}@cluster0.a5qfl.mongodb.net/?retryWrites=true&w=majority`
135+
`mongodb+srv://fullstack:${password}@cluster0.a5qfl.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0`
140136

141137
mongoose.set('strictQuery', false)
142138
mongoose.connect(url)
@@ -179,7 +175,7 @@ Tuhotaan oletusarvoisen nimen saanut kanta <i>test</i>. Päätetään käyttää
179175

180176
```js
181177
const url =
182-
`mongodb+srv://fullstack:${password}@cluster0.a5qfl.mongodb.net/noteApp?retryWrites=true&w=majority`
178+
`mongodb+srv://fullstack:${password}@cluster0.a5qfl.mongodb.net/noteApp?retryWrites=true&w=majority&appName=Cluster0`
183179
```
184180

185181
Suoritetaan ohjelma uudelleen:
@@ -359,7 +355,7 @@ const mongoose = require('mongoose')
359355

360356
// ÄLÄ KOSKAAN TALLETA SALASANOJA GitHubiin!
361357
const url =
362-
`mongodb+srv://fullstack:${password}@cluster0.a5qfl.mongodb.net/?retryWrites=true&w=majority`
358+
`mongodb+srv://fullstack:${password}@cluster0.a5qfl.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0`
363359

364360
mongoose.set('strictQuery',false)
365361
mongoose.connect(url)
@@ -503,7 +499,7 @@ npm install dotenv
503499
Sovelluksen juurihakemistoon tehdään sitten tiedosto nimeltään <i>.env</i>, jonne tarvittavien ympäristömuuttujien arvot määritellään. Tiedosto näyttää seuraavalta:
504500

505501
```bash
506-
MONGODB_URI=mongodb+srv://fullstack:[email protected]/noteApp?retryWrites=true&w=majority
502+
MONGODB_URI=mongodb+srv://fullstack:[email protected]/noteApp?retryWrites=true&w=majority&appName=Cluster0
507503
PORT=3001
508504
```
509505

@@ -548,7 +544,7 @@ Koska Fly.io ei hyödynnä gitiä, menee myös .env-tiedosto Fly.io:n palvelimel
548544
ja asettaa ympäristömuuttujan arvo komennolla:
549545

550546
```
551-
fly secrets set MONGODB_URI='mongodb+srv://fullstack:[email protected]/noteApp?retryWrites=true&w=majority'
547+
fly secrets set MONGODB_URI='mongodb+srv://fullstack:[email protected]/noteApp?retryWrites=true&w=majority&appName=Cluster0'
552548
```
553549

554550
Koska .env-tiedosto määrittelee myös ympäristömuuttujan PORT arvon, on .env:in ignorointi oikeastaan välttämätöntä jotta sovellus ei yritä käynnistää itseään väärään portiin.

src/content/images/3/mongo2.png

-156 KB
Loading

src/content/images/3/mongo3.png

-99.8 KB
Loading

src/content/images/3/mongo4.png

-163 KB
Loading

src/content/images/3/mongo5.png

-121 KB
Loading

src/content/images/3/mongo6new.png

-41.4 KB
Loading

src/content/images/3/mongo7.png

-96.6 KB
Loading

src/content/images/3/mongo8new.png

-123 KB
Loading

src/content/images/3/mongo9.png

-79.3 KB
Loading

0 commit comments

Comments
 (0)