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
4. Deploy to Modelence Cloud
To deploy your Data API to cloud:- Create a Cloud Environment: In your Modelence Cloud dashboard, navigate to your application and create a new environment, selecting cloud as the environment type.
- Get the Deployment Command: Go to your cloud environment’s settings page and copy the deployment command:
- Deploy: Run the deployment command in your project directory. The deployment process will:
- Build your application
- Upload it to Modelence Cloud
- Provision resources including MongoDB database and server infrastructure
- Launch your application
active and you’ll receive a URL to access your deployed Data API.
Core Components
DB Access
MongoDB is configured when you create an environment. During environment creation, you can choose to:- Create a new MongoDB database, or
- Connect to an existing MongoDB instance
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 /data/v1/action/findOne)
Purpose: Retrieve a single document from a collection
Request Fields:
2. Find Multiple Documents (POST /data/v1/action/find)
Purpose: Retrieve multiple documents from a collection
Request Fields:
3. Insert One Document (POST /data/v1/action/insertOne)
Purpose: Insert a single document into a collection
Request Fields:
4. Insert Multiple Documents (POST /data/v1/action/insertMany)
Purpose: Insert multiple documents into a collection
Request Fields:
5. Update One Document (POST /data/v1/action/updateOne)
Purpose: Update a single document in a collection
Request Fields:
6. Update Multiple Documents (POST /data/v1/action/updateMany)
Purpose: Update multiple documents in a collection
Request Fields:
7. Replace One Document (POST /data/v1/action/replaceOne)
Purpose: Replace an entire document in a collection
Request Fields:
8. Delete One Document (POST /data/v1/action/deleteOne)
Purpose: Delete a single document from a collection
Request Fields:
9. Delete Multiple Documents (POST /data/v1/action/deleteMany)
Purpose: Delete multiple documents from a collection
Request Fields:
10. Aggregate (POST /data/v1/action/aggregate)
Purpose: Perform aggregation operations on a collection
Request Fields:
11. Count Documents (POST /data/v1/action/countDocuments)
Purpose: Count the number of documents matching a filter
Request Fields:
12. Estimated Document Count (POST /data/v1/action/estimatedDocumentCount)
Purpose: Get an estimated count of all documents in a collection (faster but less accurate than countDocuments)
Request Fields:
13. Distinct (POST /data/v1/action/distinct)
Purpose: Get distinct values for a specific field across documents
Request Fields:
14. Find One and Update (POST /data/v1/action/findOneAndUpdate)
Purpose: Find a single document and update it atomically, returning either the original or updated document
Request Fields:
15. Find One and Replace (POST /data/v1/action/findOneAndReplace)
Purpose: Find a single document and replace it entirely, returning either the original or replacement document
Request Fields:
16. Find One and Delete (POST /data/v1/action/findOneAndDelete)
Purpose: Find a single document and delete it atomically, returning the deleted document
Request Fields:
17. Bulk Write (POST /data/v1/action/bulkWrite)
Purpose: Perform multiple write operations (insert, update, replace, delete) in a single request
Request Fields:
insertOne:{ "insertOne": { "document": {...} } }updateOne:{ "updateOne": { "filter": {...}, "update": {...}, "upsert": false } }updateMany:{ "updateMany": { "filter": {...}, "update": {...}, "upsert": false } }replaceOne:{ "replaceOne": { "filter": {...}, "replacement": {...}, "upsert": false } }deleteOne:{ "deleteOne": { "filter": {...} } }deleteMany:{ "deleteMany": { "filter": {...} } }
18. Create Index (POST /data/v1/action/createIndex)
Purpose: Create an index on a collection to improve query performance
Request Fields:
19. Drop Index (POST /data/v1/action/dropIndex)
Purpose: Remove an index from a collection
Request Fields:
20. List Indexes (POST /data/v1/action/listIndexes)
Purpose: List all indexes on a collection
Request Fields:
21. List Collections (POST /data/v1/action/listCollections)
Purpose: List all collections in a database
Request Fields:
22. Create Collection (POST /data/v1/action/createCollection)
Purpose: Create a new collection in a database
Request Fields:
23. Drop Collection (POST /data/v1/action/dropCollection)
Purpose: Delete a collection and all its documents
Request Fields:
24. List Databases (POST /data/v1/action/listDatabases)
Purpose: List all available databases
Request Fields:
25. Run Command (POST /data/v1/action/runCommand)
Purpose: Execute arbitrary database commands
Request Fields:
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