yeps-mongoose
v1.0.3
Published
YEPS Mongoose connector
Downloads
23
Maintainers
Readme
YEPS Mongoose
YEPS Promise based Mongoose client
How to install
npm i -S yeps-mongoose
How to use
Config
config/default.json
{
"mongoose": {
"uri": "mongodb://localhost/test",
"parameters": {
"useMongoClient": true
}
}
}
Middleware
const App = require('yeps');
const error = require('yeps-error');
const logger = require('yeps-logger');
const server = require('yeps-server');
const app = new App();
app.all([
error(),
logger(),
]);
app.then(async (ctx) => {
const { Schema } = ctx.mongoose;
const UserSchema = new Schema({
name: {
type: String,
required: [true, 'Name is required.'],
},
});
const User = mongoose.model('user', UserSchema);
const test = new User({ name: 'Test' });
await test.save();
const users = await User.find({ name: 'Test' });
const user = await User.findOne({ _id: test._id });
await test.remove();
});
server.createHttpServer(app);
Module
const mongoose = require('yeps-mongoose/mongoose');
const { Schema } = mongoose;
const UserSchema = new Schema({
name: {
type: String,
required: [true, 'Name is required.'],
},
});
const User = mongoose.model('user', UserSchema);
module.exports = User;