Skip to content

Commit 2396348

Browse files
Merge branch 'docs/adding-mongoose-session-section' of https://github.com/ahmedwael216/docs.nestjs.com into ahmedwael216-docs/adding-mongoose-session-section
2 parents ab77686 + 6443f68 commit 2396348

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

content/techniques/mongo.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,15 @@ export class CatsService {
193193
}
194194
```
195195

196+
### Sessions
197+
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.
198+
199+
```typescript
200+
const session = await this.connection.startSession();
201+
session.startTransaction();
202+
203+
```
204+
196205
#### Multiple databases
197206

198207
Some projects require multiple database connections. This can also be achieved with this module. To work with multiple connections, first create the connections. In this case, connection naming becomes **mandatory**.

0 commit comments

Comments
 (0)