Skip to content

Instantly share code, notes, and snippets.

@stcalica
Last active January 30, 2024 22:33
Show Gist options
  • Save stcalica/b2228419ea1e1e763ceb82a4c86c61c9 to your computer and use it in GitHub Desktop.
Save stcalica/b2228419ea1e1e763ceb82a4c86c61c9 to your computer and use it in GitHub Desktop.
Using the Data API in Mongo DB Postman Workspace

MongoDB Data API Introduction

The MongoDB Data API provides REST-like access to your data in MongoDB Atlas, a MongoDB database-as-a-service.

For full documentation, visit the MongoDB Data API documentation website.

Getting Started

  1. Create a free MongoDB Atlas cluster. Choose the dataset sample if you need sample data. Create a cluster

  2. Fork this collection into your workspace for use with your variables.

  3. Enable the Data API in your running cluster. Enable Data API Access

  4. Copy the Data API URL endpoint from the Atlas UI and paste it into the 'URL_ENDPOINT' collection variable. Grab the URL Endpoint

  5. Grant Data API access to your cluster. Grant Data API

  6. Create a new API key in the Atlas UI, copy the value, and paste it into the 'API_KEY' collection variable. Create a new API Key

With the EJSON format, you can leverage MongoDB’s Extended JSON format for various data types.

For writes, use the 'CONTENT_TYPE' variable set to either 'json' or 'ejson' in the Content-Type header.

For reads, the Data API defaults to JSON but can be changed to EJSON by setting the Accept header. Adjust the 'ACCEPT_TYPE' variable to 'json' or 'ejson' to control the Accept header in Postman requests. The default content type in Atlas can also be changed in the Atlas Admin UI.

Fill in other variables with your cluster, database, and collection names.

Now you can explore endpoints and perform CRUD operations on your collection using the MongoDB Data API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment