Skip to content

Commit e7e7f1c

Browse files
committed
docs(techniques/mongo): added sessions section
added a small section on how to start a new session using the connection object
1 parent aa98a05 commit e7e7f1c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

content/techniques/mongo.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ import { Connection } from 'mongoose';
191191
export class CatsService {
192192
constructor(@InjectConnection() private connection: Connection) {}
193193
}
194+
```
195+
### Sessions
196+
To start a session with mongoose you shouldn't use `mongoose.startSession()` directly. Instead inject the connection using [@InjectConnection](http://localhost:4200/techniques/mongodb#connection), then use the connection object to start the session.
197+
198+
```typescript
199+
const session = await this.connection.startSession();
200+
session.startTransaction();
201+
194202
```
195203

196204
#### Multiple databases

0 commit comments

Comments
 (0)