Skip to content

Commit d206d11

Browse files
committed
Update README
1 parent fa1d488 commit d206d11

File tree

1 file changed

+36
-65
lines changed

1 file changed

+36
-65
lines changed

README.md

Lines changed: 36 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,42 @@
22
<img src="/logo.png" height="120px" />
33
</p>
44

5-
# mongodb-data-api
5+
# mongodb-data-api-fetch
66

7-
[![GitHub stars](https://img.shields.io/github/stars/surmon-china/mongodb-data-api.svg?style=for-the-badge)](https://github.com/surmon-china/mongodb-data-api/stargazers)
7+
[![GitHub stars](https://img.shields.io/github/stars/trophologist/mongodb-data-api-fetch.svg?style=for-the-badge)](https://github.com/trophologist/mongodb-data-api-fetch/stargazers)
88
&nbsp;
9-
[![npm](https://img.shields.io/npm/v/mongodb-data-api?color=c7343a&label=npm&style=for-the-badge)](https://www.npmjs.com/package/mongodb-data-api)
9+
[![npm](https://img.shields.io/npm/v/mongodb-data-api-fetch?color=c7343a&label=npm&style=for-the-badge)](https://www.npmjs.com/package/mongodb-data-api-fetch)
1010
&nbsp;
11-
[![Test Codecov](https://img.shields.io/codecov/c/github/surmon-china/mongodb-data-api?style=for-the-badge)](https://codecov.io/gh/surmon-china/mongodb-data-api)
12-
&nbsp;
13-
[![GitHub license](https://img.shields.io/github/license/surmon-china/mongodb-data-api.svg?style=for-the-badge)](/LICENSE)
11+
[![GitHub license](https://img.shields.io/github/license/trophologist/mongodb-data-api-fetch.svg?style=for-the-badge)](/LICENSE)
1412

15-
MongoDB Atlas [Data API](https://www.mongodb.com/docs/atlas/api/data-api/) SDK for Node.js.
13+
MongoDB Atlas [Data API](https://www.mongodb.com/docs/atlas/api/data-api/) SDK for Cloudflare Workers.
1614

17-
---
15+
Fully compatible with https://github.com/surmon-china/mongodb-data-api/
1816

1917
### Installation
2018

2119
```bash
22-
npm install mongodb-data-api --save
20+
npm install mongodb-data-api-fetch --save
2321
```
2422

2523
or
2624

2725
```bash
28-
yarn add mongodb-data-api
26+
yarn add mongodb-data-api-fetch
2927
```
3028

3129
### Usage
3230

3331
#### Init
3432

3533
```ts
36-
import { createMongoDBDataAPI } from 'mongodb-data-api'
34+
import { createMongoDBDataAPI } from 'mongodb-data-api-fetch'
3735

3836
// init by URL Endpoint
3937
const api = createMongoDBDataAPI({
4038
apiKey: '<your_mongodb_api_key>',
41-
urlEndpoint: 'https://data.mongodb-api.com/app/<your_mongodb_app_id>/endpoint/data/v1'
39+
urlEndpoint:
40+
'https://data.mongodb-api.com/app/<your_mongodb_app_id>/endpoint/data/v1'
4241
})
4342

4443
// or init by app ID
@@ -76,52 +75,40 @@ See [MongoDB Data API Resources](https://www.mongodb.com/docs/atlas/api/data-api
7675
1. find a single document
7776

7877
```ts
79-
api
80-
.findOne({
81-
dataSource: '<target_cluster_name>',
82-
database: '<target_database_name>',
83-
collection: '<target_collection_name>',
84-
filter: { name: 'Surmon' }
85-
})
86-
.then((result) => {
87-
console.log(result.document)
88-
})
78+
const { document } = await api.findOne({
79+
dataSource: '<target_cluster_name>',
80+
database: '<target_database_name>',
81+
collection: '<target_collection_name>',
82+
filter: { name: 'Surmon' }
83+
})
8984
```
9085

9186
2. insert a single document
9287

9388
```ts
94-
api
95-
.insertOne({
96-
dataSource: '<target_cluster_name>',
97-
database: '<target_database_name>',
98-
collection: '<target_collection_name>',
99-
document: {
100-
name: 'Surmon',
101-
age: 19
102-
}
103-
})
104-
.then((result) => {
105-
console.log(result.insertedId)
106-
})
89+
const { insertedId } = await api.insertOne({
90+
dataSource: '<target_cluster_name>',
91+
database: '<target_database_name>',
92+
collection: '<target_collection_name>',
93+
document: {
94+
name: 'Surmon',
95+
age: 19
96+
}
97+
})
10798
```
10899

109100
3. run an aggregation pipeline
110101

111102
```ts
112-
api
113-
.aggregate({
114-
dataSource: '<target_cluster_name>',
115-
database: '<target_database_name>',
116-
collection: '<target_collection_name>',
117-
pipeline: [
118-
{ $match: { status: 'urgent' } },
119-
{ $group: { _id: '$productName', sumQuantity: { $sum: '$quantity' } } }
120-
]
121-
})
122-
.then((result) => {
123-
console.log(result.documents)
124-
})
103+
const { document } = await api.aggregate({
104+
dataSource: '<target_cluster_name>',
105+
database: '<target_database_name>',
106+
collection: '<target_collection_name>',
107+
pipeline: [
108+
{ $match: { status: 'urgent' } },
109+
{ $group: { _id: '$productName', sumQuantity: { $sum: '$quantity' } } }
110+
]
111+
})
125112
```
126113

127114
#### Method chaining
@@ -193,25 +180,9 @@ const customerCollection = new MongoDBDataAPI<CustomerDocument>(
193180
const customer = await customerCollection.findOne({ ... })
194181
```
195182

196-
### Development
197-
198-
```bash
199-
# install dependencies
200-
yarn
201-
202-
# lint
203-
yarn lint
204-
205-
# test
206-
yarn test
207-
208-
# build
209-
yarn build
210-
```
211-
212183
### Changelog
213184

214-
Detailed changes for each release are documented in the [release notes](/CHANGELOG.md).
185+
Please refer to https://github.com/surmon-china/mongodb-data-api/
215186

216187
### License
217188

0 commit comments

Comments
 (0)