A Node.js command-line interface tool that allows data seeding and deletion in MongoDB databases.
This CLI tool works directly from your terminal. It provides two primary functionalities:
- Import data from JSON files to your MongoDB collections
- Delete documents from selected MongoDB collections
The tool includes validation to ensure only valid data is imported, with detailed logging and error reporting.
- Node.js (v14.0.0 or higher)
- npm
- MongoDB connection (local or remote)
- Clone the repository:
git clone https://github.com/yourusername/mongo-cli-tool.git
cd mongo-cli-tool- Install dependencies:
npm install- Create a
.envfile with your MongoDB connection string:
MONGO_URI=mongodb+srv://yourusername:yourpassword@cluster0.mongodb.net/yourdb
- Make the CLI executable (Unix/Linux/macOS):
chmod +x mongo-cli.jsnode mongo-cli.js --help--file <filename>: Path to JSON file--model <model>: Model name to use (e.g., ZStation)--collection <name>: MongoDB collection name
node mongo-cli.js --import --file data.json --model ZStation --collection stationsnode mongo-cli.js --delete --file data.json --model ZStation --collection stations# Import Z-Stations data
node mongo-cli.js --import --file zstations_transformed.json --model ZStation --collection stations
# Delete all Z-Stations data
node mongo-cli.js --delete --file zstations_transformed.json --model ZStation --collection stations- Data validation before import
- Colorful console output for better readability
- Detailed error reporting
- Progress tracking during operations
Currently, the following models are supported:
ZStation- for fuel station data
To add more models, update the modelMap object in mongo-cli.js.
To add new models:
- Create a new model file in the
modelsdirectory - Add the model to the
modelMapobject inmongo-cli.js
This project is licensed under the MIT License - see the LICENSE file for details.
Erekle Sesiashvili - GitHub
