From 26173752797718502694d13686c7a7c4a5bfad30 Mon Sep 17 00:00:00 2001 From: nodkz Date: Mon, 29 Oct 2018 20:09:53 +0600 Subject: [PATCH] feat: add `onlyOnDemandIndexing` option to disable middleware hooks Related #50 --- README.md | 2 +- lib/index.js | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 472bf8f..930bfd9 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/lib/index.js b/lib/index.js index ebeb1b4..a5b2a58 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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; @@ -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);