In this post, we take a look at How to Import and Export JSON Data using MongoDB Compass. In this method we would be making use of the GUI interface for importing the JSON data that would be usable for working with the database. And there is also another method where you can use the command line to upload the JSON data, for import and export to MongoDB database.
What you need for this tutorial? You need MongoDB installed, along with utilities like mongod and the mongodb compass working. You should test out if the connection for the mongodb compass is working fine. You can turn on the service and make sure to run it to check if it connects. Once verified try this tutorial.
If you are short on time, go through video tutorial below as it would save you time and you would get visual idea too.
I assume you have MongoDB installed and also mongod service running. And you can now also make sure to open the MongoDB Compass. This would open up the MongoDB interface on the browser and you would be able to upload and also export the database through the browser.
So let's go step by step here.
- Connect to the MongoDB database through connection.
- Provide the connection string, parameters required for the connection.
- Create a database. Give that database a name.
- Create a collection, give it a name too.
- Now it's time to upload the JSON data.
- Click on Add data dropdown in the interface
- Choose your JSON file.
- Upload the file and wait for the confirmation of data upload
- Click import
This should import the data into the database. And this would be visible into the MongoDB compass. Where you can see how the data appears and how it can be usable through the queries or through even the GUI. You would be able to see the same results with the CSV data too. However I wish to cover that using another tutorial next week.
How does Mongoimport command line works?
This is another method which we can cover in the free time. You can easily use this method but it requires some level of command knowledge and you can type it in while running the mongod and also get the data uploaded.
Use the below command. I am attaching image so that it'd be easier for you to keep for reference. You can use ray.so like me to make such code images.
That's it for now. I have managed to import the JSON data into the MongoDB. And for this tutorial I have made use of the MongoDB compass. And if everything works properly I can make use of the utility for development of the variety of the import and export. I have covered both options whichever option works for you that you can go for it.
I hope you like this video and also follow the channel. Like, share and subscribe as that would continue to motivate me to make more content. And the best part there would be some benefit for me in this as the revenue would keep the food on table. YouTube has playlist feature which you can use to keep the videos from me in a list you can keep for reference.
If you happen to like this content, do give me feedback over there and that would help me improve my efforts in near future.
Su publicación ha sido votada por @Edu-venezuela, se trasladará a otros proyectos de curación para obtener más apoyo. ¡Continúe con el buen trabajo!
Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!
Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).
You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support.