2022-08-13 09:30:04 +01:00
|
|
|
---
|
2022-08-16 11:58:34 +01:00
|
|
|
categories:
|
|
|
|
- Databases
|
2022-08-20 15:00:05 +01:00
|
|
|
tags: [mongo-db, node-js]
|
2022-08-13 09:30:04 +01:00
|
|
|
---
|
|
|
|
|
|
|
|
# Importing data to MongoDB
|
|
|
|
|
|
|
|
We can use the command line to import data into a Mongo database. We can also combine the importing of data with the creation of a database:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
mongoimport --db [preexisting_or_new_database name] --collection [collection_name] --file sourcedata.json --jsonArray
|
|
|
|
```
|
|
|
|
|
2022-08-16 11:58:34 +01:00
|
|
|
We use `--jsonArray` to indicate the format of the data we are importing.
|
2022-08-13 09:30:04 +01:00
|
|
|
|
|
|
|
Once this has executed, the data will be visible in Compass.
|