mission05_mongo
v1.0.0
Published
Auction item search application using MongoDB and Express.
Readme
Auction CLI Tool
A Node.js command-line utility for managing auction items in a MongoDB database. This tool allows you to list, add, update, delete, search, and seed auction items directly from the terminal.
Installation
Prerequisites
- Node.js (v14 or higher)
- MongoDB (running locally)
Steps to Install
Clone the repository:
git clone <your-repository-url> cd <your-repository-name>Install dependencies:
npm installStart MongoDB:
Make sure MongoDB is running locally. You can start it with:
mongodRun the CLI Tool:
The CLI tool is located in the
cli.jsfile, which you can use to interact with the auction database. Use the following command:npm run <command>The available commands are detailed below.
Usage
Commands
Seed the database:
Populate the database with initial auction items from a sample JSON file.
npm run seedThis command will:
- Clear any existing items in the
auctionDBcollection. - Insert new items from the
auction_items.jsonfile into the database.
- Clear any existing items in the
Search auction items:
Search for auction items by their title or description.
auction-cli search <query>Example:
auction-cli search "bike"This command will search the database for auction items matching the given search query and display the results.
List all auction items:
List all auction items in the database.
auction-cli listExample output:
Found 3 auction items: 1. ID: 123456 - Road Bike - Lightweight road bike with a comfortable design $200 2. ID: 789101 - Antique Vase - A beautiful and rare antique vase from the 18th century $500Add a new auction item:
Add a new auction item to the database with the title, description, and price.
auction-cli add <title> <description> <price>Example:
auction-cli add "Laptop" "A brand new gaming laptop" 1200This command will add a new auction item with the given details to the database.
Delete an auction item by ID:
Delete an auction item from the database by its unique ID.
auction-cli delete <id>Example:
auction-cli delete 1234567890abcdef12345678This command will delete the item with the specified ID.
Update an auction item by ID:
Update the details (title, description, price) of an auction item using its unique ID.
auction-cli update <id> <title> <description> <price>Example:
auction-cli update 1234567890abcdef12345678 "Updated Laptop" "A newly updated gaming laptop" 1300This command will update the auction item with the given ID.
Help Command
To display help information about the available commands and options:
auction-cli --help
### Key Updates:
- The command to **seed the database** is now referenced with `npm run seed` instead of directly running the `seed.cjs` file.
- **Running the application** is done with `npm start`, which will execute the `server.cjs` file.
- You can still use the `auction-cli` commands like `search`, `list`, `add`, `update`, and `delete` from the terminal.
Let me know if anything else needs to be adjusted!