Skip to main content
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

Project Setup

1. Create a new application

2. Connect to Modelence Cloud

  1. Open cloud.modelence.com create
  2. Create a new application and a local environment
  3. Click on Setting → Set up
  4. Follow the steps described in the modal

3. Start the Development Server

Your Data API will be available at http://localhost:3000

4. Deploy to Modelence Cloud

To deploy your Data API to cloud:
  1. Create a Cloud Environment: In your Modelence Cloud dashboard, navigate to your application and create a new environment, selecting cloud as the environment type.
  2. Get the Deployment Command: Go to your cloud environment’s settings page and copy the deployment command:
  1. 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
Once deployment completes, your environment status will become 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 the DATA_API_KEY environment variable). Use the apiKey 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:
Response:
Then use the access token in the Authorization header:
Access tokens expire after 30 minutes. Use the refresh token to obtain a new access token without re-authenticating.

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:
Example Request:
Response:

2. Find Multiple Documents (POST /data/v1/action/find)

Purpose: Retrieve multiple documents from a collection Request Fields:
Example Request:
Response:

3. Insert One Document (POST /data/v1/action/insertOne)

Purpose: Insert a single document into a collection Request Fields:
Example Request:
Response:

4. Insert Multiple Documents (POST /data/v1/action/insertMany)

Purpose: Insert multiple documents into a collection Request Fields:
Example Request:
Response:

5. Update One Document (POST /data/v1/action/updateOne)

Purpose: Update a single document in a collection Request Fields:
Example Request:
Response:

6. Update Multiple Documents (POST /data/v1/action/updateMany)

Purpose: Update multiple documents in a collection Request Fields:
Example Request:
Response:

7. Replace One Document (POST /data/v1/action/replaceOne)

Purpose: Replace an entire document in a collection Request Fields:
Example Request:
Response:

8. Delete One Document (POST /data/v1/action/deleteOne)

Purpose: Delete a single document from a collection Request Fields:
Example Request:
Response:

9. Delete Multiple Documents (POST /data/v1/action/deleteMany)

Purpose: Delete multiple documents from a collection Request Fields:
Example Request:
Response:

10. Aggregate (POST /data/v1/action/aggregate)

Purpose: Perform aggregation operations on a collection Request Fields:
Example Request:
Response:

11. Count Documents (POST /data/v1/action/countDocuments)

Purpose: Count the number of documents matching a filter Request Fields:
Example Request:
Response:

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:
Example Request:
Response:

13. Distinct (POST /data/v1/action/distinct)

Purpose: Get distinct values for a specific field across documents Request Fields:
Example Request:
Response:

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:
Example Request:
Response:

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:
Example Request:
Response:

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:
Example Request:
Response:

17. Bulk Write (POST /data/v1/action/bulkWrite)

Purpose: Perform multiple write operations (insert, update, replace, delete) in a single request Request Fields:
Operation Types:
  • 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": {...} } }
Example Request:
Response:

18. Create Index (POST /data/v1/action/createIndex)

Purpose: Create an index on a collection to improve query performance Request Fields:
Example Request:
Response:

19. Drop Index (POST /data/v1/action/dropIndex)

Purpose: Remove an index from a collection Request Fields:
Example Request:
Response:

20. List Indexes (POST /data/v1/action/listIndexes)

Purpose: List all indexes on a collection Request Fields:
Example Request:
Response:

21. List Collections (POST /data/v1/action/listCollections)

Purpose: List all collections in a database Request Fields:
Example Request:
Response:

22. Create Collection (POST /data/v1/action/createCollection)

Purpose: Create a new collection in a database Request Fields:
Example Request:
Response:

23. Drop Collection (POST /data/v1/action/dropCollection)

Purpose: Delete a collection and all its documents Request Fields:
Example Request:
Response:

24. List Databases (POST /data/v1/action/listDatabases)

Purpose: List all available databases Request Fields:
Example Request:
Response:

25. Run Command (POST /data/v1/action/runCommand)

Purpose: Execute arbitrary database commands Request Fields:
Example Request:
Response:

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