W3Schools.com (2024)

MongoDB Data API

The MongoDB Data API can be used to query and update data in a MongoDB database without the need for language specific drivers.

Language drivers should be used when possible,but the MongoDB Data API comes in handy when drivers are not available or drivers are overkill for the application.

Read & Write with the MongoDB Data API

The MongoDB Data API is a pre-configured set of HTTPS endpoints that can be used to read and write data to a MongoDB Atlas database.

With the MongoDB Data API, you can create, read, update, delete, or aggregate documents in a MongoDB Atlas database.

Cluster Configuration

In order to use the Data API, you must first enable the functionality from the Atlas UI.

From the MongoDB Atlas dashboard, navigate to Data API in the left menu.

Select the data source(s) you would like to enable the API on and click Enable the Data API.

Access Level

By default, no access is granted. Select the access level you'd like to grant the Data API. The choices are: No Access, Read Only, Read and Write, or Custom Access.

Data API Key

In order to authenticate with the Data API, you must first create a Data API key.

Click Create API Key, enter a name for the key, then click Generate API Key.

Be sure to copy the API key and save it somewhere safe. You will not get another chance to see this key again.

Sending a Data API Request

We can now use the Data API to send a request to the database.

In the next example, we'll use curl to find the first document in the movies collection of our sample_mflix database.We loaded this sample data in theIntro to Aggregations section.

To run this example, you'll need your App Id, API Key, and Cluster name.

You can find your App Id in the URL Endpoint field of the Data API page in the MongoDB Atlas UI.

Example

curl --location --request POST 'https://data.mongodb-api.com/app/<DATA API APP ID>/endpoint/data/v1/action/findOne' \--header 'Content-Type: application/json' \--header 'Access-Control-Request-Headers: *' \--header 'api-key: <DATA API KEY>' \--data-raw '{ "dataSource":"<CLUSTER NAME>", "database":"sample_mflix", "collection":"movies", "projection": {"title": 1}}'

Try it Yourself »

Data API Endpoints

In the previous example, we used the findOne endpoint in our URL.

There are several endpoints available for use with the Data API.

All endpoints start with the Base URL:https://data.mongodb-api.com/app/<Data API App ID>/endpoint/data/v1/action/

Find a Single Document

Endpoint

POST Base_URL/findOne

The findOne endpoint is used to find a single document in a collection.

Request Body

Example

{ "dataSource": "<data source name>", "database": "<database name>", "collection": "<collection name>", "filter": <query filter>, "projection": <projection>}

Find Multiple Documents

Endpoint

POST Base_URL/find

The find endpoint is used to find multiple documents in a collection.

Request Body

Example

{ "dataSource": "<data source name>", "database": "<database name>", "collection": "<collection name>", "filter": <query filter>, "projection": <projection>, "sort": <sort expression>, "limit": <number>, "skip": <number>}

Insert a Single Document

Endpoint

POST Base_URL/insertOne

The insertOne endpoint is used to insert a single document into a collection.

Request Body

Example

{ "dataSource": "<data source name>", "database": "<database name>", "collection": "<collection name>", "document": <document>}

Insert Multiple Documents

Endpoint

POST Base_URL/insertMany

The insertMany endpoint is used to insert multiple documents into a collection.

Request Body

Example

{ "dataSource": "<data source name>", "database": "<database name>", "collection": "<collection name>", "documents": [<document>, <document>, ...]}

Update a Single Document

Endpoint

POST Base_URL/updateOne

Request Body

Example

{ "dataSource": "<data source name>", "database": "<database name>", "collection": "<collection name>", "filter": <query filter>, "update": <update expression>, "upsert": true|false}

Update Multiple Documents

Endpoint

POST Base_URL/updateMany

Request Body

Example

{ "dataSource": "<data source name>", "database": "<database name>", "collection": "<collection name>", "filter": <query filter>, "update": <update expression>, "upsert": true|false}

Delete a Single Document

Endpoint

POST Base_URL/deleteOne

Request Body

Example

{ "dataSource": "<data source name>", "database": "<database name>", "collection": "<collection name>", "filter": <query filter>}

Delete Multiple Documents

Endpoint

POST Base_URL/deleteMany

Request Body

Example

{ "dataSource": "<data source name>", "database": "<database name>", "collection": "<collection name>", "filter": <query filter>}

Aggregate Documents

Endpoint

POST Base_URL/aggregate

Request Body

Example

{ "dataSource": "<data source name>", "database": "<database name>", "collection": "<collection name>", "pipeline": [<pipeline expression>, ...]}

W3schools Pathfinder

Track your progress - it's free!

W3Schools.com (2024)
Top Articles
How to Read Your Credit Card Statement - NerdWallet
Accredited Investor Questionnaire - NW Corporate Law
Robinhood Turbotax Discount 2023
Seething Storm 5E
877-668-5260 | 18776685260 - Robocaller Warning!
craigslist: south coast jobs, apartments, for sale, services, community, and events
Atrium Shift Select
Youtube Combe
Erin Kate Dolan Twitter
Hillside Funeral Home Washington Nc Obituaries
D10 Wrestling Facebook
Munich residents spend the most online for food
Commodore Beach Club Live Cam
Willam Belli's Husband
Urban Airship Expands its Mobile Platform to Transform Customer Communications
Florida History: Jacksonville's role in the silent film industry
Prestige Home Designs By American Furniture Galleries
Transactions (zipForm Edition) | Lone Wolf | Real Estate Forms Software
EASYfelt Plafondeiland
Where to eat: the 50 best restaurants in Freiburg im Breisgau
Ou Class Nav
Weve Got You Surrounded Meme
Reicks View Farms Grain Bids
Costco Jobs San Diego
Cornedbeefapproved
Ou Football Brainiacs
Delta Township Bsa
Amazing Lash Bay Colony
Missing 2023 Showtimes Near Mjr Southgate
Supermarkt Amsterdam - Openingstijden, Folder met alle Aanbiedingen
Texas Baseball Officially Releases 2023 Schedule
Naya Padkar Newspaper Today
Rogers Centre is getting a $300M reno. Here's what the Blue Jays ballpark will look like | CBC News
Cl Bellingham
Kelley Blue Book Recalls
Noaa Marine Weather Forecast By Zone
My Locker Ausd
Cl Bellingham
Grand Valley State University Library Hours
Citymd West 146Th Urgent Care - Nyc Photos
Marcal Paper Products - Nassau Paper Company Ltd. -
The Sports Academy - 101 Glenwest Drive, Glen Carbon, Illinois 62034 - Guide
Aloha Kitchen Florence Menu
9294027542
tampa bay farm & garden - by owner "horses" - craigslist
Richard Mccroskey Crime Scene Photos
Fredatmcd.read.inkling.com
Amourdelavie
Craigslist Monterrey Ca
Skybird_06
Famous Dave's BBQ Catering, BBQ Catering Packages, Handcrafted Catering, Famous Dave's | Famous Dave's BBQ Restaurant
Latest Posts
Article information

Author: Jeremiah Abshire

Last Updated:

Views: 6409

Rating: 4.3 / 5 (74 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Jeremiah Abshire

Birthday: 1993-09-14

Address: Apt. 425 92748 Jannie Centers, Port Nikitaville, VT 82110

Phone: +8096210939894

Job: Lead Healthcare Manager

Hobby: Watching movies, Watching movies, Knapping, LARPing, Coffee roasting, Lacemaking, Gaming

Introduction: My name is Jeremiah Abshire, I am a outstanding, kind, clever, hilarious, curious, hilarious, outstanding person who loves writing and wants to share my knowledge and understanding with you.