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
- Log in to Craveva AI dashboard
- Navigate to Data Sources
- Click Connect New Data Source
- Select Database as connection type
- Choose MongoDB from database types
- Choose connection method:
- Enable SSL/TLS if using MongoDB Atlas
- Click Test Connection
- If successful, click Save
- - Connection String: Paste your full connection string
- - Individual Fields: Enter host, port, database, username, password
Step 3: Verify Connection
- Your MongoDB connection should appear in the Data Sources list
- Status should show Connected
- You can see which collections are available
Step 4: Analyze Your Schema
- Go to Agent Builder
- Click Create New Agent
- Select your MongoDB data source
- In Schema Analysis step, you'll see:
- Review the detected schema
- - All your collections
- - Document structure
- - Field types
Step 5: Map Your Data
- Move to Data Mapping step
- Use AI Assistant to filter collections:
- Review the Entity Relationship graph
- The AI will suggest relationships between collections
- - Example: "Show only sales and order collections"
Step 6: Create Your Agent
- Configure agent settings
- Test with sample queries
- 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
Related Guides
Connecting Database
Learn how to connect PostgreSQL, MySQL, MongoDB, and other databases to Craveva AI for data analysis...
Connecting REST API
Step-by-step guide to connect REST APIs to Craveva AI for data integration and AI agent creation....
Connecting GraphQL API
Step-by-step guide to connect GraphQL APIs to Craveva AI for data integration and AI agent creation....