Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions skills/mongodb/SKILL.md
Original file line number Diff line number Diff line change
@@ -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')`.*
17 changes: 17 additions & 0 deletions skills/mongodb/resources/ai_rules.md
Original file line number Diff line number Diff line change
@@ -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.
29 changes: 29 additions & 0 deletions skills/mongodb/resources/setup_instructions.md
Original file line number Diff line number Diff line change
@@ -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.
23 changes: 23 additions & 0 deletions skills/mongodb/scripts/install_mongodb.ps1
Original file line number Diff line number Diff line change
@@ -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."
29 changes: 29 additions & 0 deletions skills/mongodb/scripts/install_mongodb.sh
Original file line number Diff line number Diff line change
@@ -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."