1 00:00:02,130 --> 00:00:08,580 Now there's one last special projection parameter which I want to show you that is related to arrays 2 00:00:09,270 --> 00:00:11,720 and that is the slice operator 3 00:00:11,730 --> 00:00:19,100 you could say. Now I'll repeat my query where I look for movies with a rating average greater than nine, 4 00:00:19,500 --> 00:00:26,490 but now I'll not use $elemMatch your on my genres but I will still use a special value enclosed in 5 00:00:26,520 --> 00:00:28,180 curly braces. 6 00:00:28,230 --> 00:00:31,920 I'll look for a slice of the genres array, 7 00:00:31,950 --> 00:00:33,360 let's say two 8 00:00:33,640 --> 00:00:39,830 and with this yields to me and for that, I will also add some 9 00:00:39,830 --> 00:00:41,260 other projection so that I don't get 10 00:00:41,260 --> 00:00:48,340 everything, I'll also add let's say the name and set it to one because now this will give me a list of items 11 00:00:48,340 --> 00:00:51,120 where I only have the ID because it's in there by default 12 00:00:51,130 --> 00:00:56,950 and I didn't exclude it, then I have the name of the series and then I have the genres but only the 13 00:00:56,950 --> 00:00:58,620 first two elements. 14 00:00:58,660 --> 00:01:04,930 So all these documents can absolutely have more genres assigned to them but I only see the first two 15 00:01:05,590 --> 00:01:10,510 because I use slice two and that can be any number, 16 00:01:10,570 --> 00:01:16,870 you can look for the first three, the first five and you can even use slice in different way. 17 00:01:16,870 --> 00:01:23,150 You can use it in the array form and then the first element is the amount of elements in the array, 18 00:01:23,170 --> 00:01:25,410 so in the genres array which you skip 19 00:01:25,510 --> 00:01:31,240 let's say one and then the second element is the amount of data you want to limit it to, let's say two. 20 00:01:31,480 --> 00:01:36,970 So now we will pull some items from the genres array but we'll skip the first item and then in this 21 00:01:36,970 --> 00:01:38,760 case, return the items 2 and 3, 22 00:01:38,800 --> 00:01:44,260 so the next two items. And now we can see that here we can't directly prove that 23 00:01:44,260 --> 00:01:46,030 but you could of course search for this element, 24 00:01:46,030 --> 00:01:49,880 let's maybe do that. Let's search for firefly by ID, 25 00:01:49,990 --> 00:01:52,490 we see science fiction and western here 26 00:01:53,080 --> 00:02:01,330 but if we quickly use our movies and we look for ID being equal to our objectId and we print this 27 00:02:01,330 --> 00:02:04,120 in a pretty format or don't need to do that, 28 00:02:04,180 --> 00:02:07,210 we can simply project out all the genres, 29 00:02:07,210 --> 00:02:08,890 so just set genres to one. 30 00:02:11,770 --> 00:02:14,190 If I now hit enter, 31 00:02:14,640 --> 00:02:21,270 I get that one entry and we see here, we pulled out science fiction and western, 32 00:02:21,360 --> 00:02:24,610 actually the genres are adventure, science fiction and western. 33 00:02:24,720 --> 00:02:29,550 So we skipped the first value and then we output the next two values, 34 00:02:29,550 --> 00:02:34,060 that is what we did with this syntax, with slice. 35 00:02:34,260 --> 00:02:39,570 So now you have a lot of different ways of controlling what you see, for normal fields it's straight 36 00:02:39,570 --> 00:02:45,860 forward with 1 and 0, for arrays, it's hard to do that with 1 and 0 or impossible to be precise, 37 00:02:45,870 --> 00:02:52,380 so there you got elemMatch, the dollar sign and slice to control which elements of the array end up in 38 00:02:52,380 --> 00:02:53,810 your result set. 39 00:02:54,120 --> 00:02:58,020 And with that, you got full control over what you fetch with filtering 40 00:02:58,170 --> 00:03:03,290 and then which fields of the found documents you include in your result set.