1 00:00:02,200 --> 00:00:04,110 Now let's import some data 2 00:00:04,180 --> 00:00:10,210 and for that, you need to exit the shell which you can do by hitting control C because you need to go 3 00:00:10,210 --> 00:00:13,750 back into your normal terminal mode on your operating system. 4 00:00:14,230 --> 00:00:18,870 Then you should navigate to a folder where you find the file, the json file 5 00:00:18,870 --> 00:00:24,940 you want to import, json files can be imported and attached to this video, you find a dummy file with 6 00:00:24,940 --> 00:00:26,040 which we'll work. 7 00:00:26,470 --> 00:00:33,130 So make sure to download that file into a folder and then with the cd command, navigate into that folder 8 00:00:33,280 --> 00:00:36,760 in your terminal, so in the folder where you stored that attached file. 9 00:00:37,850 --> 00:00:41,230 I already am in such a folder, now in there, 10 00:00:41,300 --> 00:00:45,780 you see I got a couple of files, we'll work with the tv-shows.json file which is the one you found the 11 00:00:45,780 --> 00:00:49,220 attached and we can now import it with the Mongo import command. 12 00:00:49,220 --> 00:00:50,780 This should be globally available 13 00:00:50,810 --> 00:00:57,500 since you added the path to your Mongo binaries to your path variables on your operating system. 14 00:00:57,500 --> 00:01:02,930 If you did not do that, you need to navigate into that folder where your binaries are, where mongod 15 00:01:02,930 --> 00:01:07,000 and so on are, where you also find mongo import and then you can execute this 16 00:01:07,100 --> 00:01:12,810 and then the first argument you pass here is the name of the file you want to import. 17 00:01:12,830 --> 00:01:17,780 Now if you're not in that same folder as the file, you'll have to specify a full path on your operating 18 00:01:17,780 --> 00:01:18,530 system, 19 00:01:18,530 --> 00:01:22,130 since I am in the same folder, I can just specify the filename. 20 00:01:22,460 --> 00:01:26,700 Then we can specify into which database you want to import that data 21 00:01:26,740 --> 00:01:30,750 and here, I'll have my movie data database which should be created on the fly, 22 00:01:30,980 --> 00:01:34,250 you specify the database with the -d command. 23 00:01:34,520 --> 00:01:39,560 You can also specify or you should specify into which collection you want to import your data then, 24 00:01:39,770 --> 00:01:45,170 so in the movie data database, I want to import it into the movies collection and in the movies collection, 25 00:01:45,480 --> 00:01:47,620 there all these documents should be added. 26 00:01:47,960 --> 00:01:53,240 Now tv-shows.json happens to hold an array of documents, not just one document, 27 00:01:53,240 --> 00:01:58,880 so you also should specify --jsonarray to make the mongo import command aware of this because 28 00:01:58,880 --> 00:02:02,380 you could also use it to import just one document which is the default 29 00:02:02,390 --> 00:02:07,150 it looks for, now with this we tell it hey there are multiple documents in that file. 30 00:02:07,190 --> 00:02:09,340 Now the last thing I'll add is --drop, 31 00:02:09,350 --> 00:02:15,620 this simply means if this collection should already exist, it will be dropped and then re-added 32 00:02:15,740 --> 00:02:20,110 otherwise it we'll append the data to the existing collection and that might also be what you want 33 00:02:20,240 --> 00:02:25,910 but here, I don't have the collection yet but if I had it, it would delete the old one and re-import the 34 00:02:25,910 --> 00:02:28,270 data into the newly created one. 35 00:02:28,580 --> 00:02:35,210 With that if I hit enter, it should connect to your running mongod process, so that still needs to be running, 36 00:02:35,390 --> 00:02:37,810 it drops movie data movies if that existed 37 00:02:37,910 --> 00:02:43,880 and then you see it imported 240 documents. And now we can fire up that shell again 38 00:02:44,750 --> 00:02:46,130 and there, if I 39 00:02:46,340 --> 00:02:47,710 have a look at my databases, 40 00:02:47,720 --> 00:02:49,740 we see the movie data, 41 00:02:50,060 --> 00:02:57,350 I can then switch to movie data and there, we should see a movies collection and if we quickly have a look 42 00:02:57,350 --> 00:03:02,480 at that with find pretty, you will see a bunch of data in there. 43 00:03:02,480 --> 00:03:05,300 Now here we have more than 20 records 44 00:03:05,480 --> 00:03:10,270 which is why I have this output here and I'll come back to cursors in the next module by the way 45 00:03:10,460 --> 00:03:17,210 but you see here we got some movie data for some series basically like supernatural, so series you 46 00:03:17,210 --> 00:03:19,500 can watch on TV, 47 00:03:19,610 --> 00:03:26,150 well we got some data on them here. So this is the data we'll also work with in the next module and Mongo 48 00:03:26,180 --> 00:03:30,900 import of course is a helpful tool for getting data you want to start with 49 00:03:30,920 --> 00:03:35,180 or you will have from an older database or whatever into your database in collection.