Skip to content

orinak/koa-mongoosejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

koa-mongoosejs

Koa middleware to integrate Mongoose.

Highly opinionated, check https://www.npmjs.com/package/koa-mongoose

Install

npm install koa-mongoosejs

Usage

const { Schema } = require('mongoose')
const db = require('koa-mongoosejs')

// setup options
const url = 'mongodb://localhost/app'
const schemas = {
  Thing: new Schema({ name: String })
}

app.use(db({ url, schemas  }))

app.use(async ctx => {
  ctx.body = await ctx
    .model('Thing')
    .find({})
    .exec()
})

License

MIT