diff --git a/skills/mongodb/SKILL.md b/skills/mongodb/SKILL.md new file mode 100644 index 00000000..b874c5c9 --- /dev/null +++ b/skills/mongodb/SKILL.md @@ -0,0 +1,22 @@ +--- +name: mongodb +description: Creates a new MongoDB project using a pre-configured development environment with custom AI rules. +--- + +## When to Use This Skill + +Use this skill when the user wants to create a new, ready-to-use MongoDB environment. The skill scaffolds a complete project with a running database server and example data. + +## Instructions + +1. **Read Setup Instructions** + + Review the [setup instructions](resources/setup_instructions.md) to understand how the project is initialized. + + *Action: Read `resources/setup_instructions.md`.* + +2. **Create the Project** + + This skill uses a script to create the project. The script will copy the necessary files and set up the initial project structure. + + *Action: `run_terminal_command(command='bash skills/mongodb/scripts/install_mongodb.sh', windowsCommand='powershell -File skills/mongodb/scripts/install_mongodb.ps1')`.* diff --git a/skills/mongodb/resources/ai_rules.md b/skills/mongodb/resources/ai_rules.md new file mode 100644 index 00000000..e6d7c29a --- /dev/null +++ b/skills/mongodb/resources/ai_rules.md @@ -0,0 +1,17 @@ +The following rules are for the AI assistant to follow when assisting with MongoDB development. + +## Query Best Practices + +* **Indexes:** Always recommend using indexes for frequently queried fields. The AI should suggest creating indexes on fields used in `find`, `sort`, and `aggregate` operations. +* **Projections:** Advise the user to use projections to limit the fields returned by a query. This reduces the amount of data transferred over the network. +* **`explain()`:** When a query is slow, suggest using the `explain()` method to analyze the query's performance. + +## Schema Design + +* **Embedding vs. Referencing:** The AI should provide guidance on when to embed documents versus when to use references. Embedding is generally preferred for one-to-one or one-to-many relationships where the data is accessed together. +* **Data Types:** Recommend using the appropriate data types for fields to optimize storage and performance. + +## Security + +* **Input Validation:** The AI should always recommend validating and sanitizing user input to prevent NoSQL injection attacks. +* **Least Privilege:** Advise the user to create database users with the minimum required permissions. diff --git a/skills/mongodb/resources/setup_instructions.md b/skills/mongodb/resources/setup_instructions.md new file mode 100644 index 00000000..af6bf707 --- /dev/null +++ b/skills/mongodb/resources/setup_instructions.md @@ -0,0 +1,29 @@ +# MongoDB Workspace Setup Instructions + +Follow these steps to initialize the workspace. + +## 1. Create the MongoDB Project + +This step uses a setup script to scaffold the new project. + +First, choose a name for your workspace (the default is `my-mongodb-project`). Then, run ONE of the following commands depending on your operating system: + +**Windows (PowerShell)** + +```powershell +powershell -File .\skills\mongodb\scripts\install_mongodb.ps1 +``` + +**macOS / Linux (bash)** + +```bash +bash ./skills/mongodb/scripts/install_mongodb.sh +``` + +This single command handles the entire project and dependency setup. + +## 2. How It Works + +This skill automates the entire setup of a new MongoDB database environment. There are no manual installation steps required. + +The setup script creates a new project directory and copies the necessary configuration files. The `.idx/dev.nix` file included in the project tells the IDX environment to automatically install and run a MongoDB server for you. diff --git a/skills/mongodb/scripts/install_mongodb.ps1 b/skills/mongodb/scripts/install_mongodb.ps1 new file mode 100644 index 00000000..b559fc62 --- /dev/null +++ b/skills/mongodb/scripts/install_mongodb.ps1 @@ -0,0 +1,23 @@ +#!/usr/bin/env pwsh + +# Prompt the user to choose a template +$template = Read-Host -Prompt "Choose a MongoDB template (express, flask, or blank)" + +while ($template -notin @('express', 'flask', 'blank')) { + Write-Host "Invalid option. Please choose 'express', 'flask', or 'blank'." + $template = Read-Host -Prompt "Choose a MongoDB template (express, flask, or blank)" +} + +# Prompt the user for a project name. +$ProjectName = Read-Host -Prompt "Enter the project name (default: my-mongodb-$template-project)" + +# If no project name is entered, use the default. +if ([string]::IsNullOrEmpty($ProjectName)) { + $ProjectName = "my-mongodb-$template-project" +} + +# Copy the pre-configured mongodb app template to the new project directory. +Write-Host "Creating project from template 'mongodb/$template'..." +Copy-Item -Path "mongodb/$template" -Destination $ProjectName -Recurse + +Write-Host "MongoDB project '$ProjectName' created successfully." diff --git a/skills/mongodb/scripts/install_mongodb.sh b/skills/mongodb/scripts/install_mongodb.sh new file mode 100644 index 00000000..995b12e8 --- /dev/null +++ b/skills/mongodb/scripts/install_mongodb.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Prompt the user to choose a template +echo "Choose a MongoDB template:" +select template in "express" "flask" "blank"; do + case $template in + express|flask|blank) + echo "You chose the '$template' template." + break + ;; + *) + echo "Invalid option. Please choose 1, 2, or 3." + ;; + esac +done + +# Prompt the user for a project name. +read -p "Enter the project name (default: my-mongodb-$template-project): " ProjectName + +# If no project name is entered, use the default. +if [ -z "$ProjectName" ]; then + ProjectName="my-mongodb-$template-project" +fi + +# Copy the pre-configured mongodb app template to the new project directory. +echo "Creating project from template 'mongodb/$template'..." +cp -r "mongodb/$template" "$ProjectName" + +echo "MongoDB project '$ProjectName' created successfully."