<commit_before>var MERGE_FIELD_FILTER = [ '_id', '__v' ];

module.exports = function(schema, options) {
  schema.method('merge', function (obj, opts) {
    var self = this;
    opts = opts || {};
    var restriction = opts.fields && !(/(^| |\+)[^ +-]+/g.test(opts.fields));
    self.schema.eachPath(function(path) {
      if (MERGE_FIELD_FILTER.indexOf(path) == -1 &&
        isMergeable(schema, path, opts, restriction)) {
          var value = getValue(obj, path);
          if (value !== undefined) self.set(path, value);
      }
    });
    return this;
  });
};<commit_msg>Add option for merging virtual fields<commit_after>var MERGE_FIELD_FILTER = [ '_id', '__v' ];

module.exports = function(schema, options) {
  schema.method('merge', function (obj, opts) {
    var self = this;
    opts = opts || {};
    var restriction = opts.fields && !(/(^| |\+)[^ +-]+/g.test(opts.fields));
    self.schema.eachPath(function(path) {
      if (MERGE_FIELD_FILTER.indexOf(path) == -1 &&
        isMergeable(schema, path, opts, restriction)) {
          var value = getValue(obj, path);
          if (value !== undefined) self.set(path, value);
      }
    });
    if (opts.virtuals) {
      Object.keys(self.schema.virtuals).forEach(function (path) {
        var value = getValue(obj, path);
        if (value !== undefined) self.set(path, value);
      });
    }
    return this;
  });
};
{'fraction_non_alphanumeric': 0.1813583815028902, 'fraction_numerical': 0.001445086705202312, 'mean_word_length': 2.8795518207282913, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6138193', 'n_tokens_mistral': 453, 'n_tokens_neox': 445, 'n_words': 96}