1.0.0 • Published 4 years ago

egg-mongod v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

egg-mongod

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Install

$ npm i egg-mongod --save

Usage

app.mongo.MongoClient.connect((err, client) => {
      if (err) {
        console.log('失败');
      } else {
        const db = client.db('egg');
        db.createCollection('mongod', function(err, res) {
          if (err) throw err;
          console.log('创建集合!');
          client.close();
          return (res);
        });
      }
    });
// {app_root}/config/plugin.js
exports.mongo = {
  enable: true,
  package: 'egg-mongo',
};

Configuration

// {app_root}/config/config.default.js
exports.mongo = {
  client: {
    username: 'egg',
    password: '123',
    hosts: '152.136.150.202',
    port: '27017',
    db: 'egg',
    query: '',
    options: { useUnifiedTopology: true },
  },
  agent: true,
  app: true,
};

see config/config.default.js for more detail.

Example

Questions & Suggestions

Please open an issue here.

License

MIT

1.0.0

4 years ago