MongoDB
MongoDB Endpoint Documentation
MongoDB Endpoint DocumentationCopied!
OverviewCopied!
MongoDB endpoints in Eden provide a comprehensive interface for interacting with MongoDB databases, collections, and documents. These endpoints support the full range of MongoDB operations, including CRUD operations, aggregation pipelines, index management, and more advanced features like GridFS and change streams.
Key FeaturesCopied!
-
Full MongoDB API Support: Coverage for all MongoDB operations from basic CRUD to advanced analytical queries
-
Aggregation Framework: Support for MongoDB's powerful pipeline-based data processing framework
-
Document Model: Native handling of MongoDB's flexible, JSON-like document model
-
GridFS Support: Built-in handling for storing and retrieving large files
-
Change Streams: Real-time notifications for database changes
-
Transactions: Support for multi-document ACID transactions
-
Index Management: Comprehensive tools for creating and managing indexes, including text and geospatial indexes
Connecting a MongoDB EndpointCopied!
Connecting to a MongoDB instance with Eden requires users to provide a the url for the mongo database, and the authentication of the provided database. The user can then define a unique name for the endpoint, and a description for the endpoint
POST /endpoints
{
"endpoint": "{{endpoint_name}}",
"kind": "Mongo",
"config": {
"auth": "None",
"read_conn": {
"url": "{{mongo_connection_url}}",
"auth": "None"
},
"write_conn": {
"url": "{{mongo_connection_url}}",
"auth": "None"
},
"content": "JSON",
"accept": "JSON",
"api_key": ""
},
"description": "mongo database description"
}
API Request StructureCopied!
All MongoDB endpoint requests follow a common structure with operation-specific variations:
{
"kind": "mongo",
"type": "[operation_type]",
"[additional_parameters]": "[values]"
}
The following API request operations are supported:
Example: Find OperationCopied!
The Find operation is one of the most commonly used MongoDB operations. Here's an example of its structure:
{
"kind": "mongo",
"type": "find",
"database": "myDatabase",
"collection": "users",
"filter": {
"age": { "$gt": 18 },
"status": "active"
},
"options": {
"projection": { "password": 0 },
"sort": { "lastName": 1, "firstName": 1 },
"skip": 0,
"limit": 100
}
}
Example: Aggregate OperationCopied!
The Aggregate operation is powerful for data processing within MongoDB:
{
"kind": "mongo",
"type": "aggregate",
"database": "myDatabase",
"collection": "orders",
"pipeline": [
{ "$match": { "status": "completed" } },
{ "$group": {
"_id": "$customer",
"totalSpent": { "$sum": "$total" },
"orderCount": { "$sum": 1 }
}},
{ "$sort": { "totalSpent": -1 } },
{ "$limit": 10 }
],
"options": {
"allowDiskUse": true,
"batchSize": 100
}
}
GridFS OperationsCopied!
GridFS is MongoDB's specification for storing and retrieving large files.
Common Configuration OptionsCopied!
Many operations accept optional configuration parameters that control their behavior:
Best PracticesCopied!
Performance Optimization
-
Index Usage:
-
Create indexes to support your queries
-
Use compound indexes for queries with multiple fields
-
Consider index ordering based on equality, sort, and range criteria
-
-
Query Efficiency:
-
Avoid scanning entire collections
-
Use projections to return only needed fields
-
Paginate results with skip and limit
-
-
Aggregation Pipeline:
-
Place
$match
and$limit
stages early in the pipeline -
Use
allowDiskUse
for large datasets -
Consider pre-aggregation for frequently used aggregations
-
Security
-
Authentication:
-
Use secure, unique credentials for MongoDB connections
-
Implement the principle of least privilege
-
Rotate credentials regularly
-
-
Data Validation:
-
Use schema validation to enforce document structure
-
Validate input before sending to MongoDB
-
Be cautious with
bypass_document_validation
-
Error Handling
-
Retry Logic:
-
Implement appropriate retry mechanisms for transient errors
-
Use exponential backoff for retries
-
Set appropriate timeouts
-
-
Connection Management:
-
Implement connection pooling
-
Monitor connection health
-
Handle connection failures gracefully
-
Monitoring and MaintenanceCopied!
-
Performance Monitoring:
-
Track operation latency
-
Monitor index usage
-
Identify slow queries
-
-
Database Maintenance:
-
Schedule regular backups
-
Plan for data growth
-
Maintain indexes
-