MongoDB Import, Export, and Database Tools

Use mongoimport, mongoexport, bsondump, and GridFS tools for practical MongoDB data movement workflows.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Import and export data
Export a collection to JSON
mongoexport --uri="mongodb://localhost:27017/appdb" --collection=users --out=users.json

# Write documents to a JSON file.

Export selected fields to CSV
mongoexport --uri="mongodb://localhost:27017/appdb" --collection=users --type=csv --fields=name,email,created_at --out=users.csv

# Create a CSV export for spreadsheets or BI tools.

Import JSON data
mongoimport --uri="mongodb://localhost:27017/appdb" --collection=users --file=users.json --jsonArray

# Load JSON documents into a collection.

Import CSV data
mongoimport --uri="mongodb://localhost:27017/appdb" --collection=users --type=csv --headerline --file=users.csv

# Load CSV rows into a collection.

Convert BSON to JSON
bsondump dump/appdb/users.bson > users.json

# Inspect dump data as JSON.

## GridFS and files
List GridFS files
mongofiles --uri="mongodb://localhost:27017/appdb" list

# Show files stored in GridFS.

Upload a file to GridFS
mongofiles --uri="mongodb://localhost:27017/appdb" put report.pdf

# Store a local file in GridFS.

Download a GridFS file
mongofiles --uri="mongodb://localhost:27017/appdb" get report.pdf

# Retrieve a file from GridFS.

Recommended next

No recommendations yet.