Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/subratomandal/dyeink/llms.txt

Use this file to discover all available pages before exploring further.

Dyeink uses MongoDB as its primary database for storing blog posts, user data, and platform metadata. This guide covers setting up MongoDB Atlas and configuring the connection.

Prerequisites

Create MongoDB Atlas Cluster

1

Create a new cluster

  1. Log in to MongoDB Atlas
  2. Click Create to create a new cluster
  3. Choose your deployment option:
    • Shared (Free tier - M0) for development
    • Dedicated for production workloads
  4. Select your cloud provider and region
    • Choose a region close to your application servers
    • AWS, Google Cloud, or Azure are all supported
  5. Name your cluster (e.g., “dyeink-production”)
  6. Click Create Cluster
The free M0 tier is perfect for development and small projects. You can upgrade later without data migration.
2

Configure network access

  1. Navigate to Network Access in the sidebar
  2. Click Add IP Address
  3. For development:
    • Click Allow Access from Anywhere (0.0.0.0/0)
  4. For production:
    • Add your server’s specific IP addresses
    • Add your deployment platform’s IP ranges (Vercel, Cloudflare Workers, etc.)
Allowing access from anywhere (0.0.0.0/0) is convenient for development but not recommended for production. Always restrict to known IP addresses.
3

Create database user

  1. Navigate to Database Access
  2. Click Add New Database User
  3. Choose Password authentication method
  4. Set a strong username and password
  5. Under Database User Privileges, select:
    • Read and write to any database for application access
    • Or create custom roles for fine-grained control
  6. Click Add User
Save the username and password securely. You’ll need them for your connection string.
4

Get connection string

  1. Navigate to Database and click Connect on your cluster
  2. Choose Connect your application
  3. Select Node.js as the driver and appropriate version
  4. Copy the connection string:
mongodb+srv://<username>:<password>@cluster.mongodb.net/?retryWrites=true&w=majority
  1. Replace <username> and <password> with your database user credentials
  2. Optionally, add the database name after the host:
mongodb+srv://username:password@cluster.mongodb.net/dyeink?retryWrites=true&w=majority

Enable Data API (Optional)

The MongoDB Data API allows HTTP-based access to your database, useful for serverless deployments.
1

Enable Data API

  1. In Atlas, navigate to App Services
  2. Click Create a New App
  3. Name your app (e.g., “DyeinkAPI”)
  4. Link it to your cluster
  5. Click Create
2

Configure Data API

  1. In your App Services application, go to HTTPS Endpoints
  2. Click Data API
  3. Enable the Data API
  4. Copy the Data API URL and API Key
  5. Configure authentication and permissions as needed
3

Set up API key

  1. Navigate to Authentication > API Keys
  2. Click Create API Key
  3. Name it (e.g., “Dyeink Production”)
  4. Copy the API key and store it securely
API keys cannot be viewed again after creation. Store them securely immediately.

Configure Database Indexes

Indexes improve query performance for your blogging platform.
1

Access the Collections

  1. Navigate to Database > Browse Collections
  2. Select your database (create one named dyeink if it doesn’t exist)
2

Create recommended indexes

For optimal performance, create these indexes:Posts collection:
// Index for published posts sorted by date
{ "status": 1, "publishedAt": -1 }

// Index for author's posts
{ "authorId": 1, "publishedAt": -1 }

// Index for slug lookups
{ "slug": 1 }

// Text index for search
{ "title": "text", "content": "text", "excerpt": "text" }
Users collection:
// Index for email lookups
{ "email": 1 }

// Index for auth provider ID
{ "auth0Id": 1 }
To create indexes via the Atlas UI:
  1. Select a collection
  2. Click the Indexes tab
  3. Click Create Index
  4. Enter the index definition
  5. Click Review and Confirm
3

Verify indexes

Use the Indexes tab to verify all indexes are created successfully and monitor their usage over time.
MongoDB Atlas provides index recommendations based on your query patterns. Check Performance Advisor regularly.

Environment Configuration

Backend (backend/.env)

# MongoDB Configuration
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/dyeink?retryWrites=true&w=majority

Root (.env)

# MongoDB Configuration
MONGODB_URI=mongodb+srv://<username>:<password>@cluster.mongodb.net/?retryWrites=true&w=majority
  • Never commit connection strings with credentials to version control
  • Use different databases for development, staging, and production
  • URL-encode special characters in passwords (e.g., @ becomes %40)

Connection String Parameters

Understand the key parameters in your MongoDB connection string:
ParameterDescriptionRecommended Value
retryWritesAutomatically retry failed write operationstrue
wWrite concern (acknowledgment level)majority
maxPoolSizeMaximum number of connections in the connection pool10 (default)
minPoolSizeMinimum number of connections to maintain0 (default)
serverSelectionTimeoutMSTimeout for server selection30000 (30s)
Example with additional parameters:
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/dyeink?retryWrites=true&w=majority&maxPoolSize=10

Verification

1

Test connection

Create a simple test script to verify connectivity:
test-connection.js
const { MongoClient } = require('mongodb');

const uri = process.env.MONGODB_URI;
const client = new MongoClient(uri);

async function testConnection() {
  try {
    await client.connect();
    console.log('✓ Connected to MongoDB');
    
    const db = client.db('dyeink');
    const collections = await db.listCollections().toArray();
    console.log('✓ Available collections:', collections.map(c => c.name));
  } catch (error) {
    console.error('✗ Connection failed:', error.message);
  } finally {
    await client.close();
  }
}

testConnection();
Run it:
node test-connection.js
2

Monitor in Atlas

  1. Navigate to Database > Cluster
  2. Click Metrics to view real-time connection and performance data
  3. Verify you see active connections from your application
3

Check application logs

Start your Dyeink backend and verify no MongoDB connection errors appear in the logs.

Performance Optimization

  • Use projection to retrieve only needed fields
  • Leverage indexes for all frequently queried fields
  • Implement pagination for large result sets
  • Use connection pooling (enabled by default)
  • Monitor slow queries in the Atlas Performance Advisor

Example: Optimized Query

// Good: Uses index, projection, and pagination
const posts = await db.collection('posts')
  .find(
    { status: 'published' },
    { projection: { title: 1, excerpt: 1, publishedAt: 1, _id: 0 } }
  )
  .sort({ publishedAt: -1 })
  .limit(20)
  .skip(page * 20)
  .toArray();

// Avoid: No index, fetches all fields, no pagination
const posts = await db.collection('posts')
  .find({ content: { $regex: /keyword/ } })
  .toArray();

Backup and Recovery

1

Enable automated backups

  1. Navigate to Backup in your cluster settings
  2. For shared clusters (M0), backups are not available (export manually)
  3. For dedicated clusters (M10+), enable Continuous Cloud Backup
  4. Configure retention policies and snapshot schedules
2

Manual backup (M0/M2/M5)

Use mongodump for manual backups:
mongodump --uri="mongodb+srv://username:password@cluster.mongodb.net/dyeink" --out=./backup
Restore with:
mongorestore --uri="mongodb+srv://username:password@cluster.mongodb.net/dyeink" ./backup/dyeink

Troubleshooting

  • Verify your IP address is whitelisted in Network Access
  • Check that your database user has correct permissions
  • Ensure your connection string is correctly formatted
  • Try connecting from a different network to rule out firewall issues
  • Verify username and password are correct
  • Check for special characters in password (they must be URL-encoded)
  • Ensure the database user has been created and has appropriate privileges
  • Try creating a new database user with a simple password to test
  • Check the Performance Advisor for index recommendations
  • Review query patterns and add appropriate indexes
  • Use explain() to analyze query execution plans
  • Consider upgrading to a larger cluster tier
  • Increase maxPoolSize in your connection string
  • Ensure connections are properly closed after use
  • Check for connection leaks in your application code
  • Monitor connection metrics in Atlas

Security Best Practices

  • Never use the default admin user for application connections
  • Create separate database users with minimal required privileges
  • Rotate database passwords regularly
  • Enable auditing on dedicated clusters
  • Use separate clusters for development and production
  • Enable TLS/SSL for all connections (enabled by default with mongodb+srv://)
  • Regularly review Database Access Logs in Atlas

Next Steps

Storage Setup

Configure Cloudflare R2 for image and media storage

Deployment

Deploy your Dyeink platform to production

Build docs developers (and LLMs) love