NOTE
This file was generated by Descript <www.descript.com>
1

00:00:00,000  -->  00:00:01,500
Hi guys and welcome back.

2

00:00:01,560  -->  00:00:02,160
In this video.

3

00:00:02,219  -->  00:00:06,000
We're going to start retrieving our
entries from MongoDB so that we're no

4

00:00:06,000  -->  00:00:08,670
longer using the Python list at all.

5

00:00:08,819  -->  00:00:09,569
Let's get started.

6

00:00:10,036  -->  00:00:12,796
Also, I suggested in the last video
that you try this on your own.

7

00:00:12,796  -->  00:00:15,496
And I would really recommend you
do that, if you haven't already.

8

00:00:16,017  -->  00:00:18,746
The first thing I'm going to do is I'm
going to hide that down a bit there

9

00:00:18,746  -->  00:00:22,342
so we have a bit more room, and then
we're going to think about where we're

10

00:00:22,342  -->  00:00:25,662
going to put our find from MongoDB.

11

00:00:26,146  -->  00:00:29,686
The first thing to do is to delete
the entries.append in there.

12

00:00:30,046  -->  00:00:34,936
And then look at where we're getting
our data from, in this code here.

13

00:00:36,046  -->  00:00:40,846
We've got the entries list and that
list is being accessed only in here.

14

00:00:41,306  -->  00:00:45,183
So this is really the
query to our data storage.

15

00:00:45,583  -->  00:00:48,703
What we want to do is where
we're accessing our data storage.

16

00:00:48,733  -->  00:00:51,193
We want to replace that
for our new data storage.

17

00:00:51,303  -->  00:00:57,063
Here we will do app.db.entries.find
and we'd put everything.

18

00:00:57,393  -->  00:00:59,743
So that is going to find
all the entries in MongoDB.

19

00:00:59,743  -->  00:01:03,153
It's going to give it back to
us as a list of dictionaries.

20

00:01:03,661  -->  00:01:07,111
And we're going to then use
them to create our tuples.

21

00:01:07,598  -->  00:01:10,898
I just said list of dictionaries
and that's not strictly true.

22

00:01:11,108  -->  00:01:14,918
It is actually a Cursor object but
it behaves very much like a list.

23

00:01:14,918  -->  00:01:20,198
So for all intents and purposes, and
for now, that is a valid thing to say.

24

00:01:20,601  -->  00:01:23,271
We've got basically a list of entries.

25

00:01:23,781  -->  00:01:27,021
What we want to do is we want to
turn them into this tuple that

26

00:01:27,021  -->  00:01:28,431
we're using in our template.

27

00:01:29,066  -->  00:01:33,746
Entry zero is the entry content,
so we'll replace that for content.

28

00:01:34,106  -->  00:01:37,616
Entry one is the entry date
so we replaced that for date.

29

00:01:37,976  -->  00:01:41,366
And here we're using entry one
as well and that is the date too.

30

00:01:41,816  -->  00:01:45,696
Notice that these are strings so they
still behave in the same way that they

31

00:01:45,696  -->  00:01:48,246
did when we were saving them to our list.

32

00:01:48,743  -->  00:01:52,373
Now I'll delete that from
there and we can try this out.

33

00:01:52,373  -->  00:01:54,113
So let me restart my app.

34

00:01:54,611  -->  00:01:57,673
Go over to the website and
refresh the page and this

35

00:01:57,673  -->  00:01:59,593
entry here should stay there.

36

00:02:00,079  -->  00:02:00,649
And it does.

37

00:02:00,679  -->  00:02:02,329
So let's add another one.

38

00:02:02,887  -->  00:02:03,897
I've written an entry there.

39

00:02:04,327  -->  00:02:06,637
Now I'm retrieving data
from MongoDB as well.

40

00:02:06,697  -->  00:02:07,537
How awesome is that?

41

00:02:07,657  -->  00:02:10,387
Because it's in the cloud,
it's not even in your computer.

42

00:02:10,627  -->  00:02:13,987
Let's add that entry there and you
can see that it comes back as well.

43

00:02:14,317  -->  00:02:19,297
Let's go over to MongoDB Compass and
make sure that it shows up there as well.

44

00:02:19,676  -->  00:02:20,526
I'm here in Compass.

45

00:02:20,546  -->  00:02:23,786
I'll click refresh and you
can see that it does appear.

46

00:02:23,846  -->  00:02:29,756
So clearly our app is connected to MongoDB
in both inserting and retrieving data.

47

00:02:30,503  -->  00:02:30,833
All right.

48

00:02:30,883  -->  00:02:32,743
That's everything for this video.

49

00:02:32,833  -->  00:02:34,393
How awesome is that?

50

00:02:34,453  -->  00:02:38,533
You've now stored and retrieved
data from MongoDB in the cloud.

51

00:02:38,923  -->  00:02:40,813
And you can do this for
any of your Python apps.

52

00:02:40,813  -->  00:02:42,673
It doesn't even have to be a Flask app.

53

00:02:42,953  -->  00:02:48,023
You can use pymongo on any command line
Python application you create as well.

54

00:02:48,083  -->  00:02:50,333
If you want to just
store and retrieve data.

55

00:02:50,693  -->  00:02:52,643
So you can see it's really that simple.

56

00:02:52,823  -->  00:02:56,093
You insert your documents into
your collection and you find them.

57

00:02:56,423  -->  00:02:59,903
And we're going to look into how
to find other types of documents

58

00:02:59,903  -->  00:03:04,043
as well, using MongoDB queries
as we go along the course too.

59

00:03:04,557  -->  00:03:04,887
All right.

60

00:03:04,887  -->  00:03:05,997
Thank you very much for joining me.

61

00:03:06,087  -->  00:03:07,467
I'll see you in the next one.
