https://github.com/andndre/deno-mongodb-atlas-data-api
A simple library that turns the long and repeating code to access the MongoDB Data API into more simple, readable, and maintainable code
https://github.com/andndre/deno-mongodb-atlas-data-api
deno mongodb-atlas-data-api
Last synced: 8 months ago
JSON representation
A simple library that turns the long and repeating code to access the MongoDB Data API into more simple, readable, and maintainable code
- Host: GitHub
- URL: https://github.com/andndre/deno-mongodb-atlas-data-api
- Owner: Andndre
- Created: 2022-08-29T10:22:13.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-03-25T02:37:35.000Z (over 3 years ago)
- Last Synced: 2025-10-20T19:54:19.568Z (8 months ago)
- Topics: deno, mongodb-atlas-data-api
- Language: TypeScript
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Deno MongoDB Atlas Data API
This is a simple library that provides an interface to the MongoDB Atlas Data API. The library can be used to perform basic CRUD (Create, Read, Update, and Delete) operations on a MongoDB database without the need for a dedicated driver.
The library is written in TypeScript, and it provides TypeScript definitions for all of its methods.
## Usage
To use the DataAPI library, you first need to initialize it with your MongoDB Atlas API key and the URL of your Data API endpoint. You can then use the insertOne, insertMany, findOne, find, updateOne, and deleteOne methods to perform CRUD operations on your database.
Here's an example of how you can use the library to insert a document into a collection:
```ts
import { DataAPI } from "https://deno.land/x/mongodbdataapi/mod.ts";
const api = DataAPI.init(
"https://data.mongodb-api.com/app/data-abcde/endpoint/data/v1/action", // remember to add "/action"!
"my-cluster",
"my-database",
"my-api-key",
);
const result = await api.insertOne("my-collection", {
name: "John Doe",
age: 42,
});
console.log(result);
```
The `init` method initializes the library with the URL of the Data API endpoint, the name of the cluster, the name of the database, and the API key. The insertOne method is then used to insert a document into the my-collection collection. The result of the operation is logged to the console.
## When to Use the Data API
*taken straight from this [documentation page](https://www.mongodb.com/docs/atlas/api/data-api/)*
You can use the Data API to integrate Atlas into any apps and services that support HTTPS requests. For example, you might:
- call the API from a serverless edge function
- access test data and log events in a CI/CD workflow
- integrate Atlas into a federated API gateway
- connect from an environment not currently supported via a MongoDB Driver or Realm SDK