Skip to content

Commit

Permalink
feat: add onlyOnDemandIndexing option to disable middleware hooks
Browse files Browse the repository at this point in the history
Related jbdemonte#50
  • Loading branch information
nodkz committed Oct 29, 2018
1 parent 3df0cb3 commit 2617375
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Options are:
* `bulk.batch` - [batchSize](https://docs.mongodb.com/manual/reference/method/cursor.batchSize/) to use on synchronise options. Defaults to 50.
* `bulk.size` - bulk element count to wait before calling `client.bulk` function. Defaults to 1000.
* `bulk.delay` - idle time to wait before calling the `client.bulk` function. Defaults to 1000.
* `onlyOnDemandIndexing` - whether or not to demand indexing on CRUD operations. If set to false middleware hooks for save, delete Defaults to true.
* `onlyOnDemandIndexing` - whether or not to demand indexing on CRUD operations. If set to true middleware hooks for save, update, delete do not fire. Defaults to false.


To have a model indexed into Elasticsearch simply add the plugin.
Expand Down
6 changes: 1 addition & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ module.exports = function(schema, options, version) {
// clone main level of options (does not clone deeper)
options = utils.highClone(options);

if (!Object.prototype.hasOwnProperty.call(options, 'onlyOnDemandIndexing')) {
options.onlyOnDemandIndexing = true;
}

const cachedMappings = new Map();

let generateType;
Expand Down Expand Up @@ -78,7 +74,7 @@ module.exports = function(schema, options, version) {
schema.methods.esUnset = unsetFields;
schema.methods.esRemove = removeDoc;

if (options.onlyOnDemandIndexing) {
if (!options.onlyOnDemandIndexing) {
schema.pre('save', preSave);
schema.post('save', postSave);
schema.post('findOneAndUpdate', postSave);
Expand Down

0 comments on commit 2617375

Please sign in to comment.