Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to import data into a mongodb database #3

Open
Aastha77Gupta opened this issue May 21, 2018 · 4 comments
Open

How to import data into a mongodb database #3

Aastha77Gupta opened this issue May 21, 2018 · 4 comments

Comments

@Aastha77Gupta
Copy link

Hi,

I am just starting to work with the technology. How should I import all the datasets on MongoDB database on my local computer.

Thank You!

@ozlerhakan
Copy link
Owner

ozlerhakan commented May 21, 2018

Hi @Aastha77Gupta ,

There are 2 different techniques to import datasets into your mongod depending on a file structure.

The mongoimport command; you can import CSV, TSV and JSON files using this terminal command. You can import a file generated using the mongoexport command as well. For example, if you download the files ending with .json (in our case Catalog.Books), you can give a database name and a collection name followed by one of the accepted files as follows:

$ mongoimport -d library -c books books.json

Another command is mongorestore; the files you want to import are called backup files and they are stored in binary format. These files exported using the one of the mongodb commands , mongodump,. Let's import the enron dataset now, we can do so using the below command:

$ mongorestore --drop enron/

The --drop option simply drops each collection of the specified database, if exists.

Note that the tree view of the exported enron dump database looks like :

enron
└── enron
    ├── messages.bson
    └── messages.metadata.json

The db is exported using the mongodump file with this command : $mongodump -d enron -o enron. We specify -o , so that the dump files exported into a folder called enron.

These are just the basic approaches. You can read more about them on the mongodb documentation.

Hope this can give you a starting point.

@ozlerhakan ozlerhakan changed the title How to import data How to import data into a mongodb database Jul 2, 2018
@MaBeuLux88
Copy link
Contributor

See new import.sh script in #7 which automates everything.

@Saurabhjha1821
Copy link

I want to read large json files having size around 15gb, how can i read it through mongodb or any method, any one's help will be highly appreciated

@kunalArya1
Copy link

Hi @Aastha77Gupta ,

To import datasets into a MongoDB database on your local computer, you can follow these steps:

1.Install MongoDB: If you haven't already done so, you'll need to download and install MongoDB on your computer. You can find the download and installation instructions on the MongoDB website.

2.Prepare your data: Make sure that your data is in a format that MongoDB can understand. This usually means that your data is in JSON format, although MongoDB can also handle other formats like CSV or BSON.

3.Start the MongoDB server: Open a terminal window and start the MongoDB server by running the "mongod" command. This will start the MongoDB daemon process in the background.

4. Import your data: Use the "mongoimport" command to import your data into MongoDB. For example, if your data is in a file called "mydata.json" and you want to import it into a database called "mydb" and a collection called "mycollection", you can run the following command:

mongoimport --db mydb --collection mycollection --file mydata.json

This will import the data in the "mydata.json" file into the "mydb" database and the "mycollection" collection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants