A tool to export MongoDB collections to JSON or CSV files
Project description
MongoDB Backup Exporter
A utility for exporting MongoDB collections to JSON or CSV format.
Features
- Export collections from MongoDB to JSON or CSV format.
- Automatically handles output directories.
- Supports exporting all collections or specified ones.
- Provides stats about each collection before exporting.
Installation PyPI
You can install mongodb-backup-exporter
directly from PyPI using pip:
pip install mongodb-backup-exporter
Installation Using Repository
-
Clone the repository:
git clone https://github.com/jorgecardona/mongodb-backup-exporter.git cd mongodb-backup-exporter
-
Install required Python packages:
Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows use: venv\Scripts\activate
Then, install the required packages:
pip install -r requirements.txt
-
Install
mongoexport
from MongoDB Command Line Database Tools Download:-
Windows: Download the MongoDB Database Tools from the MongoDB official site. After installation, ensure that the
mongoexport
executable is in your system's PATH. -
Linux: You can install the MongoDB Database Tools using the package manager for your distribution. For example, on Ubuntu, you can do:
sudo apt-get install mongodb-database-tools
Alternatively, you can download the tools from the MongoDB official site.
-
Usage
To use the MongoDBBackupExporter
, you can instantiate it in your script:
from mongodb_backup_exporter import MongoDBBackupExporter
# Configuration for MongoDB connection
username = "your_username" # MongoDB username
password = "your_password" # MongoDB password
hostname = "your_cluster.mongodb.net" # MongoDB cluster address
db_name = "your_database_name" # Database name
mongoexport_path = "path/to/mongoexport" # Path to mongoexport executable
# Create an instance of MongoDBBackupExporter
exporter = MongoDBBackupExporter(
username=username, # The username for the MongoDB database
password=password, # The password for the MongoDB database
hostname=hostname, # The cluster address for the MongoDB connection
db_name=db_name, # The name of the database to be backed up
mongoexport_path=mongoexport_path, # Path to the mongoexport executable
output_format='json', # Specifies the format for the exported files; can be 'json' or 'csv'
output_dir='output_directory_path', # Directory where output files will be saved; defaults to current working directory if None
)
# Execute the export process
# This method will export the specified collections from the MongoDB database
# to the designated output directory in the specified format.
exporter.execute_export()
Requirements
- Python 3.6 or higher
pymongo
library (install viapip install pymongo
)mongoexport
must be installed and accessible in your system's PATH.
License
This project is licensed under the MIT License. See the LICENSE file for details.
This version clearly specifies the installation steps for `mongoexport` on both Windows and Linux, making it easier for users to follow.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mongodb-backup-exporter-0.0.2.tar.gz
.
File metadata
- Download URL: mongodb-backup-exporter-0.0.2.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a784bd9b169edc33e15e2d5c23e1195d8792a9e3446d6a020c1d2be7bf0271ee |
|
MD5 | 72a17a46883648bd68d01e81cc548569 |
|
BLAKE2b-256 | 36ebf73bac643e77508638d2e289ab6af7ec594bd1a2b6d716d87f98b9a67ba0 |
File details
Details for the file mongodb_backup_exporter-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: mongodb_backup_exporter-0.0.2-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0e197ebd457c03ee5cba2e18051117d9efffc88cd0c3103d7a9366bb61d3cfc |
|
MD5 | 40b568768d6be2dfa56600ea9f2a0f24 |
|
BLAKE2b-256 | 0d653cf267e6bacda70342c9c182b7c804525505ab3fc616dd95a805796b72b5 |