1.0.3-0.9.2-230305-01 • Published 1 year ago
@cylution/moleculer-db-adapter-mongoose v1.0.3-0.9.2-230305-01
moleculer-db-adapter-mongoose
Mongoose adapter for Moleculer DB service
Features
Install
$ npm install moleculer-db moleculer-db-adapter-mongoose mongoose --save
Usage
"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
broker.createService({
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}
}))
});
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
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
})
Test
$ npm test
In development with watching
$ npm run ci
License
The project is available under the MIT license.
Contact
Copyright (c) 2016-2022 MoleculerJS
1.0.3-0.9.2-230305-01
1 year ago
1.0.3-0.9.2-230214-01
1 year ago
1.0.3-0.9.2-230214-02
1 year ago
1.0.3-0.9.1-221231-01
1 year ago
1.0.3-0.9.1
1 year ago
1.0.3-0.9.1-1
1 year ago
1.0.2-5
2 years ago
1.0.2-6
2 years ago
1.0.1
2 years ago
1.0.0
2 years ago
1.0.2-3
2 years ago
1.0.2-2
2 years ago
1.0.2-4
2 years ago
1.0.2-1
2 years ago
1.0.2-alpha.0
2 years ago
0.8.16
3 years ago
0.8.15
3 years ago
0.8.14
3 years ago
0.8.13
3 years ago
0.8.13-0
3 years ago
0.8.12
3 years ago
0.8.11
3 years ago
0.8.10
3 years ago