Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including moleculer-db-adapter-mongoose with all npm packages installed. Try it out:

require("moleculer/package.json"); // moleculer is a peer dependency. require("mongoose/package.json"); // mongoose is a peer dependency. var moleculerDbAdapterMongoose = require("moleculer-db-adapter-mongoose")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

moleculer-db-adapter-mongoose v0.7.2

Mongoose adapter for Moleculer DB service

Moleculer logo

moleculer-db-adapter-mongoose NPM version

Mongoose adapter for Moleculer DB service



$ npm install moleculer-db moleculer-db-adapter-mongoose mongoose --save


"use strict";

const { ServiceBroker } = require("moleculer");
const DbService = require("moleculer-db");
const MongooseAdapter = require("moleculer-db-adapter-mongoose");
const mongoose = require("mongoose");

const broker = new ServiceBroker();

// Create a Mongoose service for `post` entities
    name: "posts",
    mixins: [DbService],
    adapter: new MongooseAdapter("mongodb://localhost/moleculer-demo"),
    model: mongoose.model("Post", mongoose.Schema({
        title: { type: String },
        content: { type: String },
        votes: { type: Number, default: 0}

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

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


Example with connection URI

new MongooseAdapter("mongodb://localhost/moleculer-db")

Example with URI and options

new MongooseAdapter("mongodb://db-server-hostname/my-db", {
    user: process.env.MONGO_USERNAME,
    pass: process.env.MONGO_PASSWORD
    keepAlive: true


$ npm test

In development with watching

$ npm run ci


The project is available under the MIT license.


Copyright (c) 2016-2018 MoleculerJS

@moleculerjs @MoleculerJS

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free