1.0.0 • Published 4 years ago
egg-mongod v1.0.0
egg-mongod
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
1.0.0
4 years ago