# mongo-data-api

> Utility functions to request MongoDB Data API

Latest version **1.0.1** (published 2022-10-12) · ISC license · 0 weekly downloads

## Install

```sh
npm install mongo-data-api
pnpm add mongo-data-api
yarn add mongo-data-api
bun add mongo-data-api
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2022-10-12 |
| First published | 2022-10-12 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 16.9 KB |
| Known vulnerabilities | 0 (+24 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | StartMeUp |
| Maintainers | startmeup |
| Keywords | MongoDB data api, MongoDB |

## Links

- npm: https://www.npmjs.com/package/mongo-data-api
- Repository: https://github.com/StartMeUp/mongodb-api
- Homepage: https://github.com/StartMeUp/mongodb-api#readme
- Issues: https://github.com/StartMeUp/mongodb-api/issues
- npm.io page: https://npm.io/package/mongo-data-api

## Dependencies (2)

- [axios](https://npm.io/package/axios.md) ^0.27.2
- [dotenv](https://npm.io/package/dotenv.md) ^16.0.2

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [@temporal-architect/claude-plugin](https://npm.io/package/@temporal-architect/claude-plugin.md) — 335 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2022-10-12
- 1.0.0 — 2022-10-12

## README

# MongoDB data API

Some preconfigured utility functions to easily request the [MongoDB Data API](https://www.mongodb.com/docs/atlas/api/data-api/).

## Setup

First add the following variables and their values to your `.env` file

```
MONGO_APP_ID=
MONGO_API_KEY=
MONGO_CLUSTER_NAME=
MONGO_DATABASE=
```

## How to use

```javascript
// import the functions you need
import {
  findMany,
  findOne,
  updateMany,
  updateOne,
  replaceOne,
  deleteMany,
  deleteOne,
  aggregate,
} from "mongo-data-api";

// all functions take 2 arguments ("collectionName", {options object}) and return a promise
// Only the data of the response is returned, not the whole response
(async () => {
  const data = await findMany("collection", { limit: 3 });
  console.log(data); // { documents: [...] }
})();
```

## Details

Every function takes 2 arguments: the collection that is requested (mandatory), and an object with various options (optional, depending on the type of request). Check also [MongoDB documentation](https://www.mongodb.com/docs/atlas/api/data-api-resources/) for more details.

Examples:

```javascript
await findOne("tasks", { filter: { text: "Do the dishes" } });
await findMany("tasks"); // returns all documents in "tasks" collection
await insertOne("tasks", {
  document: { completed: false, text: "Go shopping" },
});
```

| Function     | Options     | Type             | Necessity | Response Data                                            |
| ------------ | ----------- | ---------------- | --------- | -------------------------------------------------------- |
| `findMany`   | filter      | object           | Optional  | { documents: [{ ... }, ...] }                            |
|              | projection  | object           | Optional  |
|              | sort        | object           | Optional  |
|              | limit       | number           | Optional  |
|              | skip        | number           | Optional  |
| `findOne`    | filter      | object           | Optional  | { document: {...} }                                      |
|              | projection  | object           | Optional  |
| `insertOne`  | document    | object           | Required  | { insertedId: "..." }                                    |
| `insertMany` | documents   | array of objects | Required  | { insertedIds: ["...", "...", ...] }                     |
| `updateOne`  | filter      | object           | Required  | { matchedCount: 0, modifiedCount: 0, upsertedId: "..." } |
|              | update      | object           | Required  |
|              | upsert      | boolean          | Optional  |
| `updateMany` | filter      | object           | Required  | { matchedCount: 0, modifiedCount: 0, upsertedId: "..." } |
|              | update      | object           | Required  |
|              | upsert      | boolean          | Optional  |
| `replaceOne` | filter      | object           | Required  | { matchedCount: 0, modifiedCount: 0, upsertedId: "..." } |
|              | replacement | object           | Required  |
|              | upsert      | boolean          | Optional  |
| `deleteOne`  | filter      | object           | Required  | { deletedCount: 1 }                                      |
| `deleteMany` | filter      | object           | Required  | { deletedCount: 26 }                                     |
| `aggregate`  | pipeline    | array of objects | Required  | { documents: [{ ... }, ...] }                            |

---
_Source: https://npm.io/package/mongo-data-api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
