koa-mongo
MongoDB middleware for koa, support connection pool.
koa-mongo is a mongodb middleware for koa, support connection pool.
-
app.use(mongo({
-
host: 'localhost',
-
port: 27017,
-
user: 'admin',
-
pass: '123456',
-
db: 'test',
-
max: 100,
-
min: 1,
-
timeout: 30000,
-
log: false
-
}));
or
-
app.use(mongo({
-
uri: 'mongodb://admin:123456@localhost:27017/test', //or url
-
max: 100,
-
min: 1,
-
timeout: 30000,
-
log: false
-
}));
-
'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);
MIT
wemall 开源微商城 ,微信商城,商城源码,三级分销,微生鲜,微水果,微外卖,微订餐---专业的o2o系统
wemall地址:
代码地址:
阅读(555) | 评论(0) | 转发(0) |