# moleculer-db-adapter-mongo

> MongoDB native adapter for Moleculer DB service.

Latest version **0.5.0** (published 2026-03-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install moleculer-db-adapter-mongo
pnpm add moleculer-db-adapter-mongo
yarn add moleculer-db-adapter-mongo
bun add moleculer-db-adapter-mongo
```

## Health

**Score 55/100 (C)** — status: active.

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

Warnings: low downloads; no esm support; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.5.0 |
| Published | 2026-03-28 |
| First published | 2017-08-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 22.x.x |
| Dependencies | 2 |
| Unpacked size | 45.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 156 |
| Author | MoleculerJS |
| Maintainers | icebob |
| Keywords | microservice, moleculer |

## Links

- npm: https://www.npmjs.com/package/moleculer-db-adapter-mongo
- Repository: https://github.com/moleculerjs/moleculer-db
- Homepage: https://github.com/moleculerjs/moleculer-db/tree/master/packages/moleculer-db-adapter-mongo#readme
- Issues: https://github.com/moleculerjs/moleculer-db/issues
- npm.io page: https://npm.io/package/moleculer-db-adapter-mongo

## Dependencies (2)

- [mongodb](https://npm.io/package/mongodb.md) ^3.6.10
- [fakerator](https://npm.io/package/fakerator.md) ^0.3.6

## Recent versions

- 0.5.0 (latest) — 2026-03-28
- 0.4.21 — 2024-08-24
- 0.4.20 — 2024-07-28
- 0.4.19 — 2023-11-12
- 0.4.18 — 2023-07-15
- 0.4.17 — 2023-02-11
- 0.4.16 — 2022-12-17
- 0.4.15 — 2022-08-15
- 0.4.14 — 2021-10-17
- 0.4.13 — 2021-08-12
- 0.4.12 — 2021-05-20
- 0.4.11 — 2021-02-15
- 0.4.10 — 2020-09-27
- 0.4.9 — 2020-06-06
- 0.4.8 — 2020-03-22
- … 18 more at https://npm.io/package/moleculer-db-adapter-mongo/versions

## README

![Moleculer logo](http://moleculer.services/images/banner.png)

# moleculer-db-adapter-mongo [![NPM version](https://img.shields.io/npm/v/moleculer-db-adapter-mongo.svg)](https://www.npmjs.com/package/moleculer-db-adapter-mongo)

MongoDB native adapter for Moleculer DB service.

## Features
- schemaless adapter
- MongoDB driver v3.0

## Install

```bash
$ npm install moleculer-db moleculer-db-adapter-mongo --save
```

## Usage

```js
"use strict";

const { ServiceBroker } = require("moleculer");
const DbService = require("moleculer-db");
const MongoDBAdapter = require("moleculer-db-adapter-mongo");

const broker = new ServiceBroker();

// Create a Mongoose service for `post` entities
broker.createService({
    name: "posts",
    mixins: [DbService],
    adapter: new MongoDBAdapter("mongodb://127.0.0.1/moleculer-demo"),
    collection: "posts"
});


broker.start()
// Create a new post
.then(() => broker.call("posts.create", {
    title: "My first post",
    content: "Lorem ipsum...",
    votes: 0
}))

// Get all posts
.then(() => broker.call("posts.find").then(console.log));
```

## Options

**Example with connection URI**
```js
new MongoDBAdapter("mongodb://127.0.0.1/moleculer-db")
```

**Example with connection URI & options**
```js
new MongoDBAdapter("mongodb://db-server-hostname/my-db", {
    keepAlive: 1
})
```

# Test
```
$ npm test
```

In development with watching

```
$ npm run ci
```

# License
The project is available under the [MIT license](https://tldrlegal.com/license/mit-license).

# Contact
Copyright (c) 2016-2024 MoleculerJS

[![@moleculerjs](https://img.shields.io/badge/github-moleculerjs-green.svg)](https://github.com/moleculerjs) [![@MoleculerJS](https://img.shields.io/badge/twitter-MoleculerJS-blue.svg)](https://twitter.com/MoleculerJS)

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