1 00:00:02,230 --> 00:00:07,510 So in the last lectures we learn about embedded or nested documents and arrays and this gives you a lot 2 00:00:07,510 --> 00:00:11,660 of flexibility to structure your data in the way you need it to be structured, 3 00:00:11,720 --> 00:00:18,910 also something I'll dive into deeper in my data schema and modeling and relations module in this course. 4 00:00:18,940 --> 00:00:24,190 One thing I want to do before I close or finish this module is I want to show you how you could access 5 00:00:24,280 --> 00:00:25,780 such structured data 6 00:00:25,900 --> 00:00:28,420 and let's start with the hobbies here. 7 00:00:28,510 --> 00:00:38,520 You can of course output that by let's say finding Albert with find and then I'll look for name, Albert 8 00:00:38,980 --> 00:00:43,070 Twostone, like this, 9 00:00:43,080 --> 00:00:46,170 now if I pretty print that, here's Albert. 10 00:00:46,320 --> 00:00:53,700 We can now access .hobbies here because find will give us that person and hobbies should give us 11 00:00:53,970 --> 00:00:55,730 access to the array here 12 00:00:55,740 --> 00:00:59,700 then, though one important thing, we should use findOne here 13 00:00:59,730 --> 00:01:04,890 so that mongodb knows we'll only have one element, so that we can directly access the fields of that 14 00:01:04,920 --> 00:01:06,650 element after fetching it, 15 00:01:06,720 --> 00:01:09,050 so after the closing parentheses. 16 00:01:09,120 --> 00:01:16,320 With this we indeed get the hobbies output here, sports and cooking and we can even search for that. If we 17 00:01:16,320 --> 00:01:25,270 want to find all passengers with a hobby of sports, what we can do is we can access hobbies here which 18 00:01:25,270 --> 00:01:26,200 is an array 19 00:01:26,300 --> 00:01:30,650 and look for sports and I'd put that in a pretty way 20 00:01:30,910 --> 00:01:36,490 and here we find Albert too, the entire document not just the sports entry because we're looking for the 21 00:01:36,490 --> 00:01:43,540 entire passenger documents where hobbies is equal to sports and mongodb is clever enough to see 22 00:01:43,660 --> 00:01:49,510 that hobbies actually is an array so it will simply look if that array has one element named sports and 23 00:01:49,510 --> 00:01:52,930 then it gives us the entire document as a result, 24 00:01:52,930 --> 00:01:56,600 so this is how we can also query such arrays. 25 00:01:56,620 --> 00:01:59,440 Now how can we query objects? 26 00:01:59,440 --> 00:02:04,570 Remember we had nested objects, nested documents in our flight data 27 00:02:04,750 --> 00:02:14,140 so here if I find all, we had the status. Now if we want to find all results with a status description 28 00:02:14,140 --> 00:02:21,940 of on time, we can use our flight data and find and now in the filter, 29 00:02:21,940 --> 00:02:26,160 we want to look for the status but the status, 30 00:02:26,290 --> 00:02:35,950 well we're interested in one of the fields of that nested document. For this, we can use status dot 31 00:02:36,670 --> 00:02:39,070 and then the nested field, 32 00:02:39,220 --> 00:02:46,510 so you use dot notation to drill into your embedded document, so .description. Important when using 33 00:02:46,510 --> 00:02:46,870 that, 34 00:02:46,900 --> 00:02:53,470 so when having a dot in here, when using such a path to a nested field, you need to wrap the entire 35 00:02:53,470 --> 00:02:58,370 term with double quotation marks though otherwise it will fail 36 00:02:58,450 --> 00:03:03,080 and now we can check where is this equal to on time. 37 00:03:03,190 --> 00:03:12,090 If I now pretty print this, I get both my flights because both have status description of on time, you 38 00:03:12,100 --> 00:03:13,000 get no error 39 00:03:13,030 --> 00:03:14,440 instead this query works, 40 00:03:14,440 --> 00:03:21,220 so we can drill into embedded documents with that dot notation. And obviously we can go one level further 41 00:03:21,370 --> 00:03:22,790 as far as we need to, 42 00:03:22,810 --> 00:03:24,890 we can also drill into details. 43 00:03:24,970 --> 00:03:34,210 So we're looking for our details here and we want to find all flights where details responsible is Max 44 00:03:34,210 --> 00:03:35,220 Schwarzmuller, 45 00:03:35,290 --> 00:03:36,620 we can do that too. 46 00:03:36,640 --> 00:03:43,000 Now I'm drilling into details responsible and I'm looking for Max Schwarzmuller here and I again find 47 00:03:43,000 --> 00:03:48,200 both flights because both have Max Schwarzmuller as a responsible person. 48 00:03:48,340 --> 00:03:53,690 So this dot notation is also something you'll see a lot in this course as this is an important syntax 49 00:03:53,750 --> 00:03:58,780 that allows you to look into embedded documents in your filters. 50 00:03:59,230 --> 00:04:00,460 And this is it for now, 51 00:04:00,460 --> 00:04:06,730 we'll dive much deeper into all of that and how to write efficient queries and how to access your data 52 00:04:06,730 --> 00:04:07,570 and work with it, 53 00:04:07,570 --> 00:04:10,300 we'll dive into all that throughout the course. 54 00:04:10,300 --> 00:04:16,180 These are the core things you got to know about how mongodb works, how you could work with it, how 55 00:04:16,180 --> 00:04:21,900 you can store update, delete and read data and how you can also structure your data. 56 00:04:21,910 --> 00:04:27,660 Now as I mentioned, we'll have a whole module where I dive into how to optimally or cleverly structure 57 00:04:27,660 --> 00:04:30,200 your data and how to work with related data 58 00:04:30,340 --> 00:04:32,380 but this is now a good start. 59 00:04:32,410 --> 00:04:37,460 Let's practice this before we learn about a different way of looking into your data.