Quick Start Tutorial: Migrate your MongoDB Data API in 30 minutes - A step-by-step guide to get started with Modelence Data API.
What is MongoDB Data API
An open-source API to read, write, and aggregate data in MongoDB. The application can be deployed to Modelence Cloud or to any other cloud provider.- CRUD Operations: Insert, find, update, and delete documents
- Advanced Querying: Aggregation pipelines and complex queries
- Database Management: Collection and index management
- Authentication: API key-based security
- MongoDB Operations: Direct access to MongoDB features
Sandbox
Try the Data API live at data-api-demo.modelence.app to explore all endpoints and test operations without setup.Project Setup
1. Create a new application
2. Connect to Modelenece Cloud
- Open cloud.modelence.com create
- Create a new application and a local environment
- Click on Setting → Set up
- Follow the steps described in the modal
3. Start the Development Server
http://localhost:3000
Core Components
DB Access
The MongoDB URL for Data API can be configured via thedataApi.mongodbUri
setting in Application → Configuration at https://cloud.modelence.com/.
The Modelence framework uses the
_system.mongodbUri
configuration to connect to MongoDB. You can configure two different MongoDB instances to separate Modelence-specific collections from those accessible via Data API.Authentication
The Data API supports two authentication methods:1. Direct API Key Authentication
Set the api key as the value of ‘dataApi.apiKey’ in Modelence Cloud from the Application page. (Alternatively you can use DATA_API_KEY environment variable). Use theapiKey
header in your requests:
2. Bearer Token Authentication
Alternatively, you can use Bearer token authentication by first obtaining an access token from the login endpoint: Login Endpoint:POST /auth/providers/api-key/login
Request:
Authorization
header:
Available Endpoints
The API provides comprehensive MongoDB operations with full request/response specifications:API Operations Reference
1. Find One Document (POST /api/findOne
)
Purpose: Retrieve a single document from a collection
Request Fields:
2. Find Multiple Documents (POST /api/find
)
Purpose: Retrieve multiple documents from a collection
Request Fields:
3. Insert One Document (POST /api/insertOne
)
Purpose: Insert a single document into a collection
Request Fields:
4. Insert Multiple Documents (POST /api/insertMany
)
Purpose: Insert multiple documents into a collection
Request Fields:
5. Update One Document (POST /api/updateOne
)
Purpose: Update a single document in a collection
Request Fields:
6. Update Multiple Documents (POST /api/updateMany
)
Purpose: Update multiple documents in a collection
Request Fields:
7. Replace One Document (POST /api/replaceOne
)
Purpose: Replace an entire document in a collection
Request Fields:
8. Delete One Document (POST /api/deleteOne
)
Purpose: Delete a single document from a collection
Request Fields:
9. Delete Multiple Documents (POST /api/deleteMany
)
Purpose: Delete multiple documents from a collection
Request Fields:
10. Aggregate (POST /api/aggregate
)
Purpose: Perform aggregation operations on a collection
Request Fields:
Advanced Operations
POST /api/countDocuments
- Count documentsPOST /api/runCommand
- Execute database commands
Database Management
GET /api/listCollections
- List all collectionsPOST /api/createCollection
- Create a new collectionPOST /api/dropCollection
- Drop a collectionGET /api/listDatabases
- List databases
Quick cURL Examples
Security Considerations
- API Key Authentication: All endpoints require a valid API key
- Input Validation: Requests are validated before processing
- Error Handling: Proper error responses without exposing sensitive information
- Rate Limiting: Consider implementing rate limiting for production use
Use Cases
The Data API is ideal for:- Admin Dashboards: Building administrative interfaces for data management
- Data Integration: Connecting external systems to your MongoDB database
- Rapid Prototyping: Quickly testing database operations and queries
- Analytics Tools: Building custom analytics and reporting tools
- Mobile Apps: Providing backend API for mobile applications
Complete Example
Want to see the full working code? Check it out on GitHub:Complete Data API Example
See the complete source code for this example on GitHub, including all endpoints and configuration.
Next Steps
- Explore the Store API Reference for advanced MongoDB operations
- Learn about Authentication for more secure authentication methods
- Check out the Modules Guide to understand how to organize your application