Skip to content

Commit 88996d9

Browse files
authored
docs(NODE-3059): document versioned api usage (#2779)
1 parent a769cf8 commit 88996d9

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

docs/CHANGES_4.0.0.md

+36
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
11
# Changes in 4.x
22

33
WIP
4+
5+
## Versioned API
6+
7+
Versioned API is a new feature in MongoDB 5.0 that allows user-selectable API versions, subsets of MongoDB server semantics, to be declared on a client. During communication with a server, clients with a declared API version will force the server to behave in a manner compatible with the API version. Declaring an API version on a client can be used to ensure consistent responses from a server, providing long term API stability for an application. The declared API version is applied to all commands run through the client, including those sent through the generic RunCommand helper. Specifying versioned API options in the command document AND declaring an API version on the client is not supported and will lead to undefined behaviour.
8+
9+
### Declare an API version on a client:
10+
11+
```javascript
12+
// Declare API version "1" for the client
13+
client = new MongoClient(uri, { serverApi: { version: '1' } });
14+
15+
cursor = client.db('database').collection('coll').find(...);
16+
```
17+
18+
### Strict mode
19+
20+
Declaring a `strict` API version will cause the MongoDB server to reject all commands that are not part of the declared API version. This includes command options and aggregation pipeline stages. For example, the following `find` call would fail because the `tailable` option is not part of version 1:
21+
22+
```javascript
23+
// Declare API version "1" for the client, with strict on
24+
client = new MongoClient(uri, { serverApi: { version: '1', strict: true } });
25+
26+
// Fails with an error
27+
cursor = client.db('database').collection('coll').find({ ... }, { tailable: true });
28+
```
29+
30+
### Deprecation Errors
31+
32+
The `deprecationErrors` option can be used to enable command failures when using functionality that is deprecated from version 1. Note that at the time of this writing, no deprecations in version 1 exist.
33+
34+
```javascript
35+
// Declare API version "1" for the client, with deprecationErrors on
36+
client = new MongoClient(uri, { serverApi: { version: '1', deprecationErrors: true } });
37+
38+
// Note: since API version "1" is the initial version, there are no deprecated commands to provide as an example yet.
39+
```

0 commit comments

Comments
 (0)