egg-mongo

2.0.0 • Public • Published

egg-mongo

Database mongo plug-in for egg provide mongo database access functions

Install

$ npm i egg-mongo --save

Configuration

Change ${app_root}/config/plugin.js to enable MongoDB plugin:

exports.mongo = {
  enable: true,
  package: 'egg-mongo',
};

Configure database information in ${app_root}/config/config.default.js:

Simple database instance

//  app/config/config.default.js
mongo: {
  url: 'mongodb://localhost:27017',
  dbname: 'dbName'
}

// app/controller/home.js class HomeController extends Controller { async index() { const testCollection = this.app.mongo.db.collection('testCollection'); collectionNames = await testCollection.find({}).toArray(); this.ctx.body = collectionNames; } }

Dependents (0)

Package Sidebar

Install

npm i egg-mongo

Weekly Downloads

14

Version

2.0.0

License

MIT

Unpacked Size

1.94 kB

Total Files

4

Last publish

Collaborators

  • haobin