In this tutorial, we will discuss imports and export in MongoDB as we know that at times we might be required to import the already build database to use the data in another database or we might need to extend the data in an already existing database so for the same preseason we required to import the database which already exists.
And at the end when we are done with all the editing and entering the data in we need to get that database as a file which we can do by exporting the database as a file to your system. And here we will learn how we can do so with the help of some examples.
Import
As we know that we can import any file from any of the formats to the database and we can make changes as per our requirements. For doing the same we can simply use mogoimport command to import any file format to the databases. For the same, we can follow the example given below.
mongoimport --db mydb --collection mycollection --file data.json --type json
The given example is fr importing a JSon file into the database as here the name of the file is data and the type is json and now we can perform any of the actions or required things as per choice.
Export
Export of files from MongoDB is also required when we have done with our editing or entering the data in the database. And as we know we can get the file in any of the custom file formats which we can learn in the documentation section of MongoDB in this section we can get the file even in the format of our choice as CSV.
And as it can also get the file convert and even simply in json format and for the same, we can follow the following command to export the file in json format. Here is an example of the same to get the file.
mongoexport --db mydb --collection mycollection --out data.json --type json
The above command will let you export a json file in to your system which is nothing but the file of data stored in mydb database already stored in the MongoDB.
To learn more about the export and importing of files in MongoDB visit: Import and Export of files into a database of MongoDB.
To learn more about the MongoDB tutorial and the solutions to the problems faced in mongoDB during working with MongoDB visit: MongoDB Problems And Tutorials
And to learn more about different other programming languages like Python and java tutorials and solutions to problems visit: beta python programming languages Solutions.