Now let's import some data
and for that, you need to exit the shell which you can do by hitting control C because you need to go
back into your normal terminal mode on your operating system.
Then you should navigate to a folder where you find the file, the json file
you want to import, json files can be imported and attached to this video, you find a dummy file with
which we'll work.
So make sure to download that file into a folder and then with the cd command, navigate into that folder
in your terminal, so in the folder where you stored that attached file.
I already am in such a folder, now in there,
you see I got a couple of files, we'll work with the tv-shows.json file which is the one you found the
attached and we can now import it with the Mongo import command.
This should be globally available
since you added the path to your Mongo binaries to your path variables on your operating system.
If you did not do that, you need to navigate into that folder where your binaries are, where mongod
and so on are, where you also find mongo import and then you can execute this
and then the first argument you pass here is the name of the file you want to import.
Now if you're not in that same folder as the file, you'll have to specify a full path on your operating
system,
since I am in the same folder, I can just specify the filename.
Then we can specify into which database you want to import that data
and here, I'll have my movie data database which should be created on the fly,
you specify the database with the -d command.
You can also specify or you should specify into which collection you want to import your data then,
so in the movie data database, I want to import it into the movies collection and in the movies collection,
there all these documents should be added.
Now tv-shows.json happens to hold an array of documents, not just one document,
so you also should specify --jsonarray to make the mongo import command aware of this because
you could also use it to import just one document which is the default
it looks for, now with this we tell it hey there are multiple documents in that file.
Now the last thing I'll add is --drop,
this simply means if this collection should already exist, it will be dropped and then re-added
otherwise it we'll append the data to the existing collection and that might also be what you want
but here, I don't have the collection yet but if I had it, it would delete the old one and re-import the
data into the newly created one.
With that if I hit enter, it should connect to your running mongod process, so that still needs to be running,
it drops movie data movies if that existed
and then you see it imported 240 documents. And now we can fire up that shell again
and there, if I
have a look at my databases,
we see the movie data,
I can then switch to movie data and there, we should see a movies collection and if we quickly have a look
at that with find pretty, you will see a bunch of data in there.
Now here we have more than 20 records
which is why I have this output here and I'll come back to cursors in the next module by the way
but you see here we got some movie data for some series basically like supernatural, so series you
can watch on TV,
well we got some data on them here. So this is the data we'll also work with in the next module and Mongo
import of course is a helpful tool for getting data you want to start with
or you will have from an older database or whatever into your database in collection.