nestjs-typegoose
Version:
A nestjs module wrapper for typegoose
72 lines (58 loc) • 1.6 kB
Markdown
---
id: multiple-connections
title: Multiple MongoDB Connections
---
To have multiple MongoDB connections one needs to add a `connectionName` string to `forRoot` and `forFeature`.
## `forRoot` usage
**app.module.ts**
```typescript
import { Module } from "@nestjs/common";
import { TypegooseModule } from "nestjs-typegoose";
export class ApplicationModule {}
```
**cat.module.ts**
```typescript
export class CatsModule {}
```
Here the CatsService will use the `other-mongodb` connection defined in the `forRoot`.
## `forRootAsync` usage
Same **cat.module.ts** as above for the `forFeature`.
**cat.module.ts**
```typescript
export class CatsModule {}
```
And for `forRootAsync` add `connectionName` to the options as well.
```typescript
export class CatsModule {}