koa-mongo
MongoDB middleware for koa, support connection pool.
koa-mongo
koa-mongo is a mongodb middleware for koa, support connection pool.
Install[code]npm i koa-mongo --save[/code]Usage[code]app.use(mongo({
host: 'localhost',
port: 27017,
user: 'admin',
pass: '123456',
db: 'test',
max: 100,
min: 1,
timeout: 30000,
log: false
}));[/code]or[code]app.use(mongo({
uri: 'mongodb://admin:123456@localhost:27017/test', //or url
max: 100,
min: 1,
timeout: 30000,
log: false
}));[/code]Example[code]'use strict';
var koa = require('koa');
var mongo = require('koa-mongo');
var app = koa();
app.use(mongo());
app.use(function* (next) {
yield this.mongo.db('test').collection('users').insert({ name: 'haha' });
this.body = yield this.mongo.db('test').collection('users').findOne();
this.mongo.db('test').collection('users').remove().then(function (res) {
console.log(res.result);
});
});
app.listen(3000);[/code]License
MIT
wemall 开源微商城 ,微信商城,商城源码,三级分销,微生鲜,微水果,微外卖,微订餐---专业的o2o系统
wemall地址:http://www.wemallshop.com
代码地址:http://js.koahub.com/home/feature/koa-mongo
duanshupeng 于 2017-06-21 10:38:16发表:
66