UNPKG

1.34 kBTypeScriptView Raw
1declare module 'mongoose' {
2 import mongodb = require('mongodb');
3
4 type ClientSessionOptions = mongodb.ClientSessionOptions;
5 type ClientSession = mongodb.ClientSession;
6
7 /**
8 * _Requires MongoDB >= 3.6.0._ Starts a [MongoDB session](https://www.mongodb.com/docs/manual/release-notes/3.6/#client-sessions)
9 * for benefits like causal consistency, [retryable writes](https://www.mongodb.com/docs/manual/core/retryable-writes/),
10 * and [transactions](http://thecodebarbarian.com/a-node-js-perspective-on-mongodb-4-transactions.html).
11 */
12 function startSession(options?: ClientSessionOptions): Promise<ClientSession>;
13
14 interface SessionOperation {
15 /** Sets the session. Useful for [transactions](/docs/transactions.html). */
16 session(session: mongodb.ClientSession | null): this;
17 }
18
19 interface SessionStarter {
20
21 /**
22 * Starts a [MongoDB session](https://www.mongodb.com/docs/manual/release-notes/3.6/#client-sessions)
23 * for benefits like causal consistency, [retryable writes](https://www.mongodb.com/docs/manual/core/retryable-writes/),
24 * and [transactions](http://thecodebarbarian.com/a-node-js-perspective-on-mongodb-4-transactions.html).
25 */
26 startSession(options?: ClientSessionOptions): Promise<ClientSession>;
27 }
28
29 interface SessionOption {
30 session?: ClientSession | null;
31 }
32}