* Creates a new ClientSession. When using the returned session in an operation * a corresponding ServerSession will be created. * * @remarks * A ClientSession instance may only be passed to operations being performed on the same * MongoClient it was started from.
(options?: ClientSessionOptions)
| 892 | * MongoClient it was started from. |
| 893 | */ |
| 894 | startSession(options?: ClientSessionOptions): ClientSession { |
| 895 | const session = new ClientSession( |
| 896 | this, |
| 897 | this.s.sessionPool, |
| 898 | { explicit: true, ...options }, |
| 899 | this.options |
| 900 | ); |
| 901 | this.s.activeSessions.add(session); |
| 902 | session.once('ended', () => { |
| 903 | this.s.activeSessions.delete(session); |
| 904 | }); |
| 905 | return session; |
| 906 | } |
| 907 | |
| 908 | /** |
| 909 | * A convenience method for creating and handling the clean up of a ClientSession. |