1.0.4 • Published 7 years ago

tmc-egg-mongoose v1.0.4

Weekly downloads
3
License
ISC
Repository
github
Last release
7 years ago

egg-mongoose

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

Egg's mongoose plugin.

Install

$ npm i egg-mongoose --save

Usage

// {app_root}/config/plugin.js
exports.mongoose = {
  enable: true,
  package: 'egg-mongoose',
};

Configuration

// {app_root}/config/config.default.js
exports.mongoose = {
  url: 'mongodb://127.0.0.1/example',
  options: {}
};

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

Multi-mongos support

// {app_root}/config/config.default.js
exports.mongoose = {
  url: 'mongodb://mongosA:27501,mongosB:27501',
  options: {}
};

Example

// app/model/user.js
module.exports = app => {
  const mongoose = app.mongoose;
  const UserSchema = new mongoose.Schema({
    userName: { type: String  },
    password: { type: String  }
  });

  return mongoose.model('User', UserSchema);
}

// app/controller/user.js
exports.index = function* (ctx) {
  ctx.body = yield ctx.model.User.find({});  // you should use upper case to access mongoose model
}

Questions & Suggestions

Please open an issue here.

Contribution

If you are a contributor, follow CONTRIBUTING.

License

MIT

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago