1 00:00:02,100 --> 00:00:05,130 So I mentioned there are more operators, now 2 00:00:05,160 --> 00:00:11,820 the best way to learn about them all and to always well have a look at them even if you're done with 3 00:00:11,820 --> 00:00:16,860 the course is of course to dive into the official documentation. There in the docs, 4 00:00:16,860 --> 00:00:19,490 if you check out the mongodb server, 5 00:00:19,700 --> 00:00:24,980 you can learn more about the crud operations which also will be interesting but if you scroll down to 6 00:00:24,980 --> 00:00:31,100 the reference there, you can click on operators and there right now in this module, we'll talk about the 7 00:00:31,100 --> 00:00:36,030 query and projection operators. And there you got the different categories that exist, 8 00:00:36,140 --> 00:00:37,990 here are the projection operators, 9 00:00:38,090 --> 00:00:40,110 the rest are query operators. 10 00:00:40,380 --> 00:00:45,370 And for example, you also see them here on the starting page, you'll see here is $gt 11 00:00:45,380 --> 00:00:46,850 which we saw before. 12 00:00:46,850 --> 00:00:52,700 Now there are a bunch of operators and I will walk through many many of them in this module to explain 13 00:00:52,760 --> 00:00:55,310 how they work and what you can do with them, 14 00:00:55,310 --> 00:01:00,170 so let's start with some comparison operators because this is of course a group of operators you'll 15 00:01:00,170 --> 00:01:01,570 use quite a bit. 16 00:01:02,060 --> 00:01:09,290 So let's go back to our database here and this is the query I ran before, runtime 60. 17 00:01:09,680 --> 00:01:16,530 Now let's say we want to search for movies where the runtime is actually lower than 60, 18 00:01:16,670 --> 00:01:19,770 we can do this by specifying a document as a value, 19 00:01:19,880 --> 00:01:24,950 remember the slide because this will then tell mongodb that we're not looking for equality which 20 00:01:24,950 --> 00:01:29,320 is just a default it assumes but that we now want to use a query operator. 21 00:01:29,410 --> 00:01:31,870 Now as a side note, there is a 22 00:01:31,880 --> 00:01:33,140 $eq operator 23 00:01:33,360 --> 00:01:41,150 and if I set this to 60, this query here is exactly equivalent to this query. 24 00:01:41,160 --> 00:01:48,850 So if I use runtime 60 like this or equal 60 does not make a difference, 25 00:01:48,870 --> 00:01:54,570 so this is simply a shortcut, the other syntax is just a shortcut to this more verbose mode. 26 00:01:55,020 --> 00:02:00,390 Now where it does make a difference because there is no equivalent is if you use something else than 27 00:02:00,440 --> 00:02:04,290 $eq, for example $ne for not equal 28 00:02:04,560 --> 00:02:07,400 and again, you find all these operators in the official docs. 29 00:02:07,400 --> 00:02:14,850 So now we're using the not equal operator to find all series or movies which are not equal or where 30 00:02:14,850 --> 00:02:18,060 the runtime is not equal to 60 minutes. 31 00:02:18,060 --> 00:02:22,060 So if I hit enter here, I get a bunch of data, 32 00:02:22,200 --> 00:02:25,010 let's make it more readable by adding pretty 33 00:02:25,530 --> 00:02:28,020 and let's check one document here, 34 00:02:28,020 --> 00:02:30,720 there we have a runtime of 30 indeed. 35 00:02:30,840 --> 00:02:32,700 Well let's check another document, 36 00:02:32,700 --> 00:02:37,490 there we have a runtime of 42, so also not 60 37 00:02:37,690 --> 00:02:40,440 and let's check a third one, there 38 00:02:40,560 --> 00:02:45,010 we have a runtime of 30. And you can check them all, 39 00:02:45,030 --> 00:02:53,140 there will be no series or no item with a runtime of 60 due to this query we executed. 40 00:02:53,140 --> 00:02:54,860 Now this is not equal to, 41 00:02:54,960 --> 00:03:03,780 of course we might be interested in searching for any series that has a runtime lower than 40 minutes, 42 00:03:03,780 --> 00:03:04,930 let's say. 43 00:03:04,980 --> 00:03:06,400 So not just not equal 44 00:03:06,410 --> 00:03:08,490 because that would also give us series 45 00:03:08,490 --> 00:03:14,710 with 60 minutes but lower than, so 40 minutes, 42, 60 that we'll all be out of the game. 46 00:03:15,330 --> 00:03:22,260 If we do that and let's again add pretty for a nicer output, we will see that there is a series with a 47 00:03:22,260 --> 00:03:23,640 runtime of 30 48 00:03:23,850 --> 00:03:31,010 and there is another item with a runtime of 30 and there should be another item with a runtime of 30. 49 00:03:31,200 --> 00:03:36,650 So you won't find any value above 40 here and it just happens to be the case that series 50 00:03:36,650 --> 00:03:39,660 typically have a runtime of 30, 42 or 60 minutes, 51 00:03:39,660 --> 00:03:40,830 so there's little in-between 52 00:03:40,830 --> 00:03:41,930 by the looks of it 53 00:03:42,510 --> 00:03:51,510 but this is now the lower than operator. So with that, we already covered ne, gt and lower than. 54 00:03:52,260 --> 00:03:55,830 There also is lower than or equal with lte, 55 00:03:55,860 --> 00:04:02,310 so the difference here simply is that if I was looking for let's say 42 and there happened to be some 56 00:04:02,310 --> 00:04:11,440 items with a runtime of 42, if I use lt, I will not find any runtime equal to 42 57 00:04:11,940 --> 00:04:21,870 but if I repeat that same command with lte, which means lower than or equal to 42, then if we scroll through, 58 00:04:22,140 --> 00:04:27,240 we will find some items with a runtime of 42. 59 00:04:27,380 --> 00:04:31,210 Let me quickly search one, here is one, 60 00:04:31,480 --> 00:04:32,930 so that's the difference. 61 00:04:32,950 --> 00:04:41,950 Now it should be pretty clear what gt and lte and gte therefore do. With gt, we find series where the 62 00:04:41,950 --> 00:04:43,720 runtime is greater than 42, 63 00:04:43,810 --> 00:04:52,820 so now we'll only have some items with 60 minutes in there like this one and of course with gte, we find 64 00:04:52,910 --> 00:04:54,370 well greater than or equal, 65 00:04:54,410 --> 00:04:56,690 so now again we'll have 60 minutes 66 00:04:56,690 --> 00:05:00,850 series like this one but we will also find some items with 67 00:05:00,890 --> 00:05:03,460 42 minutes of runtime. 68 00:05:03,500 --> 00:05:08,060 Now you might not find one with scrolling through the set but keep in mind because we get back a cursor, 69 00:05:08,120 --> 00:05:10,740 we only see the first 20 results of our query, 70 00:05:10,820 --> 00:05:13,650 so there might be no 42 minute series in there. 71 00:05:13,700 --> 00:05:17,090 You will get back results greater than or equal to 42 72 00:05:17,090 --> 00:05:17,840 with this query.