Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Commit

Permalink
Merge 945dfa7 into 09216b4
Browse files Browse the repository at this point in the history
  • Loading branch information
florianbepunkt committed Oct 27, 2018
2 parents 09216b4 + 945dfa7 commit 280fec2
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/index.js
Expand Up @@ -9,6 +9,11 @@ const mongoose = require('mongoose');
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, 'indexAutomatically')) {
options.indexAutomatically = true;
}

const cachedMappings = new Map();

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

schema.pre('save', preSave);
schema.post('save', postSave);
schema.post('findOneAndUpdate', postSave);

schema.post('remove', postRemove);
schema.post('findOneAndRemove', postRemove);
if (options.indexAutomatically) {
schema.pre('save', preSave);
schema.post('save', postSave);
schema.post('findOneAndUpdate', postSave);
schema.post('remove', postRemove);
schema.post('findOneAndRemove', postRemove);
}
};

module.exports.v2 = function(schema, options) {
Expand Down

0 comments on commit 280fec2

Please sign in to comment.