mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 00:39:49 +00:00
Merge pull request #2370 from jacargentina/fix-2257
Allow customization for mongoose connection (ej. load some mongoose plugins)
This commit is contained in:
commit
e819432b40
@ -130,6 +130,26 @@ module.exports = {
|
||||
};
|
||||
```
|
||||
|
||||
### Bookshelf, Mongoose
|
||||
|
||||
**Path —** `./config/functions/bookshelf.js`.
|
||||
**Path —** `./config/functions/mongoose.js`.
|
||||
|
||||
When present, they are loaded to let you customize your database connection instance, for example for adding some plugin, customizing parameters, etc.
|
||||
|
||||
As an example, for using the `mongoose-simple-random` plugin for MongoDB, you can register it like this:
|
||||
|
||||
**Path —** `./config/functions/mongoose.js`.
|
||||
```js
|
||||
'use strict';
|
||||
|
||||
const random = require('mongoose-simple-random');
|
||||
|
||||
module.exports = (mongoose, connection) => {
|
||||
mongoose.plugin(random);
|
||||
};
|
||||
```
|
||||
|
||||
***
|
||||
|
||||
## Locales
|
||||
|
@ -60,7 +60,7 @@ module.exports = function(strapi) {
|
||||
'config',
|
||||
'functions',
|
||||
'bookshelf.js'
|
||||
))(ORM, strapi.connections[connectionName]);
|
||||
))(ORM, connection);
|
||||
} catch (err) {
|
||||
// This is not an error if the file is not found.
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
// Public node modules.
|
||||
const url = require('url');
|
||||
const path = require('path');
|
||||
const _ = require('lodash');
|
||||
const mongoose = require('mongoose');
|
||||
const Mongoose = mongoose.Mongoose;
|
||||
@ -89,6 +90,18 @@ module.exports = function (strapi) {
|
||||
return cb(errMsg);
|
||||
}
|
||||
|
||||
try {
|
||||
// Require `config/functions/mongoose.js` file to customize connection.
|
||||
require(path.resolve(
|
||||
strapi.config.appPath,
|
||||
'config',
|
||||
'functions',
|
||||
'mongoose.js'
|
||||
))(instance, connection);
|
||||
} catch (err) {
|
||||
// This is not an error if the file is not found.
|
||||
}
|
||||
|
||||
Object.keys(options, key => instance.set(key, options[key]));
|
||||
|
||||
const mountModels = (models, target, plugin = false) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user