# testcontainers-mongoose

> Testcontainer mongo with mongoose

Latest version **4.2.4** (published 2025-04-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install testcontainers-mongoose
pnpm add testcontainers-mongoose
yarn add testcontainers-mongoose
bun add testcontainers-mongoose
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.2.4 |
| Published | 2025-04-09 |
| First published | 2022-03-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 6.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Yubin, Hsu |
| Maintainers | yubintw |
| Keywords | docker, testcontainers, mongoose |

## Links

- npm: https://www.npmjs.com/package/testcontainers-mongoose
- Repository: https://github.com/yubinTW/testcontainers-mongoose
- Issues: https://github.com/yubinTW/testcontainers-mongoose/issues
- npm.io page: https://npm.io/package/testcontainers-mongoose

## Dependencies (3)

- [mongoose](https://npm.io/package/mongoose.md) ^8.13.2
- [testcontainers](https://npm.io/package/testcontainers.md) ^10.24.1
- [@testcontainers/mongodb](https://npm.io/package/@testcontainers/mongodb.md) ^10.24.1

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 4.2.4 (latest) — 2025-04-09
- 4.2.3 — 2025-02-08
- 4.2.2 — 2025-01-22
- 4.2.1 — 2024-12-05
- 4.2.0 — 2024-04-22
- 4.1.6 — 2024-04-13
- 4.1.4 — 2024-03-03
- 4.1.3 — 2024-01-20
- 4.1.2 — 2024-01-13
- 4.1.1 — 2023-12-12
- 4.1.0 — 2023-12-11
- 4.0.0 — 2023-12-11
- 3.0.2 — 2023-12-08
- 3.0.1 — 2023-11-26
- 3.0.0 — 2023-11-01
- … 29 more at https://npm.io/package/testcontainers-mongoose/versions

## README

# Testcontainers-mongoose

[![Node.js CI](https://github.com/yubinTW/testcontainers-mongoose/actions/workflows/node.js.yml/badge.svg)](https://github.com/yubinTW/testcontainers-mongoose/actions/workflows/node.js.yml)
[![NPM version](https://img.shields.io/npm/v/testcontainers-mongoose.svg?style=flat)](https://www.npmjs.com/package/testcontainers-mongoose)

a mongoose helper for using testcontainers with mongodb

https://www.npmjs.com/package/testcontainers-mongoose

## Installation

```
npm i -D testcontainers-mongoose
```

if using mongoose `7.x` version

```
npm i -D testcontainers-mongoose@2.2.2
```

## Configuration

[Reference](https://github.com/testcontainers/testcontainers-node#configuration)

### Logs

- `DEBUG=testcontainers` Enable testcontainers logs
- `DEBUG=testcontainers:containers` Enable container logs
- `DEBUG=testcontainers*` Enable all logs

## Testcontainers

- `TESTCONTAINERS_RYUK_DISABLED=true` Disable ryuk
- `RYUK_CONTAINER_IMAGE=registry.mycompany.com/mirror/ryuk:0.3.0` Custom image for ryuk

## Usage

Testing with Vitest

```typescript
import * as dbHandler from 'testcontainers-mongoose'
import { describe, beforeAll, afterAll, afterEach, it, expect } from 'vitest'

describe('testcontainers-mongoose test', () => {
  beforeAll(async () => {
    await dbHandler.connect('harbor.yourcompany.com/mongo:4.4.4')
    // ...
  })
  afterAll(async () => {
    await dbHandler.closeDatabase()
  })

  afterEach(async () => {
    await dbHandler.clearDatabase()
  })

  it('some test using mongoose', async () => {
    // ...
  })
})
```

## Start Mongo Container without connect with mongoose

In case you want to connect the mongo by yourself

using `startedMongoTestContainerOf`

Get the mongo connection string by `.getUri()`

Example

```typescript
import { startedMongoTestContainerOf, StartedMongoTestContainer } from 'testcontainers-mongoose'
import { describe, beforeAll, afterAll, afterEach, it, expect } from 'vitest'

describe('testcontainers-mongoose test', () => {
  let mongoTestContainer: StartedMongoTestContainer
  beforeAll(async () => {
    mongoTestContainer = await startedMongoTestContainerOf('harbor.yourcompany.com/mongo:4.4.4')
    // connect to mongoTestContainer by yourself
    // mongoTestContainer.getUri() is the connection string of the mongo container
  })
  afterAll(async () => {
    await mongoTestContainer.closeDatabase()
  })

  afterEach(async () => {
    await mongoTestContainer.clearDatabase()
  })

  it('some test case', async () => {
    // ...
  })
})
```

---
_Source: https://npm.io/package/testcontainers-mongoose · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
