Skip to main content

Overview

DevAurva uses MongoDB with Mongoose ODM for data persistence. The application stores custom plan requests and card plan submissions in MongoDB collections.

Database Dependencies

The following packages are used for database operations:
  • mongoose (v8.9.6) - MongoDB object modeling for Node.js
  • mongodb (v6.13.0) - Official MongoDB driver

MongoDB Connection Setup

The MongoDB connection is established in server.js:12-15 using Mongoose:
import mongoose from 'mongoose';

// Connect to MongoDB
mongoose.connect(process.env.MONGODB_URI)
    .then(() => console.log('Connected to MongoDB'))
    .catch(err => console.error('MongoDB connection error:', err));

Setting Up MongoDB

1
Create a MongoDB Atlas account
2
  • Visit MongoDB Atlas
  • Sign up for a free account
  • Create a new cluster (free tier is sufficient for development)
  • 3
    Configure database access
    4
  • In the Atlas dashboard, go to Database Access
  • Click Add New Database User
  • Create a username and password
  • Set user privileges to Read and write to any database
  • Click Add User
  • 5
    Whitelist IP addresses
    6
  • Go to Network Access in the Atlas dashboard
  • Click Add IP Address
  • For development, you can click Allow Access from Anywhere (0.0.0.0/0)
  • For production, add your server’s specific IP address
  • 7
    Allowing access from anywhere (0.0.0.0/0) is convenient for development but not recommended for production. Always restrict access to specific IP addresses in production environments.
    8
    Get your connection string
    9
  • Go to Database in the Atlas dashboard
  • Click Connect on your cluster
  • Select Connect your application
  • Choose Node.js as the driver
  • Copy the connection string
  • 10
    Add connection string to .env
    11
    Add the MongoDB URI to your .env file:
    12
    MONGODB_URI=mongodb+srv://username:[email protected]/devaurva?retryWrites=true&w=majority
    
    13
    Replace:
    14
  • username with your database username
  • password with your database password
  • cluster.mongodb.net with your actual cluster hostname
  • devaurva with your preferred database name
  • Database Models

    DevAurva uses two primary MongoDB models:

    CustomPlan Model

    Stores custom website plan requests with selected features (server.js:6):
    import CustomPlan from './server/models/CustomPlan.js';
    
    Stored Data:
    • Client name, email, phone
    • Company name
    • Selected features with pricing
    • Website type
    • Total price
    • Additional notes

    CardPlan Model

    Stores predefined plan selections (server.js:7):
    import CardPlan from './server/models/CardPlan.js';
    
    Stored Data:
    • Client name, email, phone
    • Website type
    • Plan type (Starter/Professional/Enterprise)
    • Plan price
    • Budget information

    Connection Configuration

    The application uses default Mongoose connection settings with:
    • retryWrites=true - Automatic retry for write operations
    • w=majority - Write concern ensuring data is written to majority of nodes

    Testing the Database Connection

    1
    Start the server
    2
    node server.js
    
    3
    Verify connection
    4
    You should see this output:
    5
    Connected to MongoDB
    Server running on port 3001
    
    6
    Test data storage
    7
    Submit a test form through your application to verify data is being saved:
    8
  • Fill out a contact form or plan request
  • Submit the form
  • Check your MongoDB Atlas dashboard under Browse Collections
  • Verify the data appears in the appropriate collection
  • Troubleshooting

    Connection Errors

    If you see MongoDB connection error in the console:
    • Verify your MONGODB_URI is correctly formatted
    • Check that your IP address is whitelisted in Atlas
    • Ensure your database user credentials are correct
    • Verify your cluster is active and not paused

    Authentication Failed

    If authentication fails:
    • Double-check your username and password in the connection string
    • Ensure special characters in passwords are URL-encoded
    • Verify the database user has proper permissions

    Network Timeout

    If you experience timeout issues:
    • Check your network connectivity
    • Verify firewall settings aren’t blocking MongoDB connections
    • Ensure your IP is whitelisted in Atlas Network Access
    Production Considerations:
    • Use a dedicated production database (separate from development)
    • Enable MongoDB authentication and use strong passwords
    • Implement proper connection pooling
    • Set up monitoring and alerts for database performance
    • Regular backups are essential - configure automated backups in Atlas
    • Consider implementing indexes for frequently queried fields

    Next Steps

    • Set up email notifications
    • Configure additional database indexes for performance
    • Set up database backup strategies
    • Monitor database usage and optimize queries

    Build docs developers (and LLMs) love