Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 16cd0f2

Browse files
committed
feat: Adds support for operation names in requests
Closes #6
1 parent 41b971f commit 16cd0f2

File tree

8 files changed

+495
-241
lines changed

8 files changed

+495
-241
lines changed

Diff for: .vscode/settings.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"typescript.enablePromptUseWorkspaceTsdk": true,
3+
"typescript.tsserver.experimental.enableProjectDiagnostics": true,
4+
"editor.formatOnSave": true,
5+
"xo.enable": true,
6+
"editor.defaultFormatter": "esbenp.prettier-vscode",
7+
"prettier.prettierPath": "./node_modules/prettier",
8+
"tailwindCSS.experimental.classRegex": [
9+
"tw`([^`]*)",
10+
"tw\\.style\\(([^)]*)\\)"
11+
],
12+
"tailwindCSS.includeLanguages": {
13+
"tsx": "jsx"
14+
}
15+
}

Diff for: .xo-config.json

-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
"space": true,
44
"nodeVersion": false,
55
"rules": {
6-
"@typescript-eslint/array-type": [
7-
"error",
8-
{ "default": "array", "readonly": "array" }
9-
],
106
"@typescript-eslint/naming-convention": "off",
117
"@typescript-eslint/no-floating-promises": "off",
128
"@typescript-eslint/parameter-properties": [

Diff for: README.md

+9-11
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
- [Create a Mongo Client](#create-a-mongo-client)
2323
- [Select a Database](#select-a-database)
2424
- [Select a Collection](#select-a-collection)
25-
- [Changing `fetch()` on the Fly](#changing-fetch-on-the-fly)
2625
- [Collection Methods](#collection-methods)
2726
- [Return Type](#return-type)
27+
- [Specifying Operation Names](#specifying-operation-names)
2828
- [Methods](#methods)
2929
- [findOne](#findone)
3030
- [find](#find)
@@ -137,7 +137,6 @@ const client = new MongoClient(options);
137137
- `options.dataSource` - `string` the `Data Source` for your Data API. On the Data API UI, this is the "Data Source" column, and usually is either a 1:1 mapping of your cluster name, or the default `mongodb-atlas` if you enabled Data API through the Atlas Admin UI.
138138
- `options.auth` - `AuthOptions` one of the authentication methods, either api key, email & password, or a custom JWT string. At this time, only [Credential Authentication](https://www.mongodb.com/docs/atlas/api/data-api/#credential-authentication) is supported.
139139
- `options.fetch?` - A custom `fetch` function conforming to the [native fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API). We recommend [cross-fetch](https://www.npmjs.com/package/cross-fetch), as it asserts a complaint `fetch()` interface and avoids you having to do `fetch: _fetch as typeof fetch` to satisfy the TypeScript compiler
140-
- `options.headers?` - Additional [Headers](https://developer.mozilla.org/en-US/docs/Web/API/Headers) to include with the request. May also be a simple object of key/value pairs.
141140

142141
## Select a Database
143142

@@ -156,15 +155,6 @@ const collection = db.collection<TSchema>(collectionName);
156155
- `collectionName` - `string` the name of the collection to connect to
157156
- `<TSchema>` - _generic_ A Type or Interface that describes the documents in this collection. Defaults to the generic MongoDB `Document` type
158157

159-
## Changing `fetch()` on the Fly
160-
161-
```ts
162-
const altDb = db.fetch(altFetch);
163-
const altCollection = db.collection<TSchema>(collectionName).fetch(altFetch);
164-
```
165-
166-
- `altFetch` - An alternate `fetch` implementation that will be used for that point forward. Useful for adding or removing retry support on a per-call level, changing the authentication required, or other fetch middleware operations.
167-
168158
## Collection Methods
169159

170160
The following [Data API resources](https://www.mongodb.com/docs/atlas/api/data-api-resources/) are supported
@@ -195,6 +185,14 @@ interface DataAPIResponse {
195185
}
196186
```
197187

188+
### Specifying Operation Names
189+
190+
To help with tracing and debugging, any Mongo Data API operation can be named by passing a string as the first parameter. This value is converted to the `x-realm-op-name` header and can be seen in the [Mongo Data API logs](https://www.mongodb.com/docs/atlas/api/data-api/#view-data-api-logs).
191+
192+
```ts
193+
const { data, error } = await collection./*operation*/("operation name for tracing", filter, options);
194+
```
195+
198196
### Methods
199197

200198
#### findOne

0 commit comments

Comments
 (0)