---
title: Importing / Exporting Data in MongoDB
description: Commands to deal with data in Mongo, mongodump, mongorestore
date: 2019-11-10
tags: MongoDB, mongodump, mongorestore
source: https://brianchildress.co/blog/import-export-data-in-mongodb
---

# Importing / Exporting Data in MongoDB

If you're using MongoDB and need to copy, move, backup, import, export, or do something with your data, here are a few commands that should help.

From the terminal, (not inside the Mongo Shell)

**Exporting**
```sh
mongodump -d < database name > -o < output file >
```

If connecting from outside the database server, you might need to pass some additional parameters.

| Parameter  | Example             |
| :--------- | :------------------ |
| --host     | mongodb.example.com |
| --port     | 23456               |
| --username | user                |
| --password | yourpass            |

_Example Use:_
```sh
mongodump --host mongodb.example.com --port 23456 --username user --password yourpass -o /database-dump-01-01-1970
```

**Importing**
```sh
mongorestore -d < database name > /path/to/database/files
```
