Skip to content

MongoDB middleware for koa, support connection pool.

Notifications You must be signed in to change notification settings

technixp/koa-mongo

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

koa-mongo

koa-mongo is a mongodb middleware for koa, support connection pool.

Install

npm i koa-mongo --save

Usage

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
}));

Example

var koa = require('koa');
var mongo = require('koa-mongo');

var app = koa();

app.use(mongo());
app.use(function* (next) {
  this.mongo.db('test').collection('users').findOne({}, function (err, doc) {
    console.log(doc);
  });

  this.body = yield this.mongo.db('test').collection('users').findOne();
});
app.listen(3000);

License

MIT

About

MongoDB middleware for koa, support connection pool.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%