mongo-rest-controller
v0.1.0
Published
mongoDB (mongoose) REST controller for microscope-web
Downloads
2
Readme
MongoRestController
mongoDB (mongoose) REST Controller for microscope-web
Dependencies
- microscope-web
- mongoose
How to use ?
** Create some model **
import mongoose from 'mongoose';
var Article = mongoose.Schema({
title: String,
description: String
});
export default mongoose.model('Article', Article);
** Register your models in dbContext & connect to mongoDB as usual : **
import mongoose from 'mongoose';
import Article from './Article';
mongoose.connect('mongodb://mcsp:[email protected]:48878/microscope');
mongoose.connection.on('error', () => console.log('mongoDB connection error'));
mongoose.connection.once('open', () => console.log('mongoDB connection open'));
** Create controller extends MongoRestController **
import MongoRestController from 'mongoRestController';
import Article from '../models/Article';
export default class ArticleController extends MongoRestController {
get baseUrl(){
return '/api/articles'
}
get model(){
return Article;
}
}
You're done !!