Back to Documentation
Data Sources10 min read

Connecting MongoDB Database

Complete guide to connect your MongoDB database, analyze collections, and create data analysis agents.

Connecting MongoDB Database

Overview

This guide shows you how to connect your MongoDB database to Craveva AI, enabling you to create powerful data analysis agents.

Prerequisites

  • MongoDB database (local or cloud like MongoDB Atlas)
  • Database connection string or credentials
  • Network access to your MongoDB instance

Step 1: Gather Connection Information

You'll need one of the following:

Option A: Connection String (Recommended)

  • Format: mongodb://username:password@host:port/database
  • Or: mongodb+srv://username:password@cluster.mongodb.net/database (for Atlas)

Option B: Individual Fields

  • Host: Your MongoDB server address
  • Port: Usually 27017 (default)
  • Database Name: Your database name
  • Username: Database user
  • Password: Database password

Step 2: Connect in Craveva

  1. Log in to Craveva AI dashboard
  2. Navigate to Data Sources
  3. Click Connect New Data Source
  4. Select Database as connection type
  5. Choose MongoDB from database types
  6. Choose connection method:
  7. Enable SSL/TLS if using MongoDB Atlas
  8. Click Test Connection
  9. If successful, click Save
  • - Connection String: Paste your full connection string
  • - Individual Fields: Enter host, port, database, username, password

Step 3: Verify Connection

  1. Your MongoDB connection should appear in the Data Sources list
  2. Status should show Connected
  3. You can see which collections are available

Step 4: Analyze Your Schema

  1. Go to Agent Builder
  2. Click Create New Agent
  3. Select your MongoDB data source
  4. In Schema Analysis step, you'll see:
  5. Review the detected schema
  • - All your collections
  • - Document structure
  • - Field types

Step 5: Map Your Data

  1. Move to Data Mapping step
  2. Use AI Assistant to filter collections:
  3. Review the Entity Relationship graph
  4. The AI will suggest relationships between collections
  • - Example: "Show only sales and order collections"

Step 6: Create Your Agent

  1. Configure agent settings
  2. Test with sample queries
  3. Deploy your agent

Connection String Examples

Local MongoDB:

```text

mongodb://localhost:27017/mydatabase

```

MongoDB Atlas:

```text

mongodb+srv://username:password@cluster.mongodb.net/mydatabase?retryWrites=true&w=majority

```

With Authentication:

```text

mongodb://username:password@host:27017/database?authSource=admin

```

Security Best Practices

  • Use read-only database users when possible
  • Enable SSL/TLS for cloud databases
  • Store credentials securely
  • Use connection strings with proper authentication
  • Regularly rotate database passwords

Troubleshooting

Connection Timeout?

  • Check firewall rules allow connections
  • Verify host and port are correct
  • For Atlas, ensure IP whitelist includes Craveva servers

Authentication Failed?

  • Verify username and password
  • Check database user has proper permissions
  • Ensure auth database is correct

SSL Error?

  • Enable SSL/TLS option in connection form
  • For Atlas, SSL is required

What's Next?

  • Create data analysis agents
  • Use AI Assistant for data mapping
  • Set up automated reporting
  • Connect multiple databases if needed