<commit_before># Mongoose Schema Migrations

Performs mongoose data migrations on document init.

## Brief Example

```javascript
var schema = new mongoose.Schema({ /* ... */ });

var currentSchemaVersion = 2;
migrations(schema, currentSchemaVersion).add({
    version: 1,
    up: function(data) {
        var nameParts = data.name.split(' ', 2);
        data.firstName = nameParts[0];
        data.lastName = nameParts[1];
        delete data.name;
    },
    down: function(data) {
        data.name = data.firstName + ' ' + data.lastName;
        delete data.firstName;
        delete data.lastName;
    }<commit_msg>Show options in README example<commit_after># Mongoose Schema Migrations

Performs mongoose data migrations on document init.

## Brief Example

```javascript
var schema = new mongoose.Schema({ /* ... */ });

var currentSchemaVersion = 2;
var opts = {
    versionKey: '__sv',   // The default
    saveOnMigration: true // Also the default
};

migrations(schema, currentSchemaVersion, opts).add({
    version: 1,
    up: function(data) {
        var nameParts = data.name.split(' ', 2);
        data.firstName = nameParts[0];
        data.lastName = nameParts[1];
        delete data.name;
    },
    down: function(data) {
        data.name = data.firstName + ' ' + data.lastName;
        delete data.firstName;
        delete data.lastName;
    }
{'fraction_non_alphanumeric': 0.1258229700073153, 'fraction_numerical': 0.0073152889539136795, 'mean_word_length': 2.768595041322314, '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': '993822', 'n_tokens_mistral': 414, 'n_tokens_neox': 411, 'n_words': 108}