<commit_before>var Promise = require('bluebird');
var async = require('async');
var options = require('./options');
var mongoose = require('mongoose');

var ModelFactory = function () {

};

ModelFactory.prototype.make = function (name, schema) {
    function checkPreconditions(callback){
        if (!name) {
            return callback(new Error('name undefined'));
        }

        if (!schema) {
            return callback(new Error('schema undefined'));
        }

        if (!mongoose) {
            return callback(new Error('mongoose undefined'));
        }

        callback(null, schema);
    }

    function makeModelFromSchema(schema, callback){
        try {
            var model = mongoose.model(name, mongoose.Schema(schema, options));

            model.findOneAndUpdateWithOptimisticConcurrencyCheck = function (obj, callback) {
                obj.meta.versionId = obj._version + 1;
                model.findOneAndUpdate({_id: obj.id, _version: obj._version}, {$inc: {_version: 1}, $set: {meta: obj.meta, resource: obj.resource, index: obj.index}, $addToSet: {tags: { $each: obj.tags}}}, function (err, doc) {
                    if (err) return callback(err);<commit_msg>Ensure that meta.versionId is a string so that vread matches correctly<commit_after>var Promise = require('bluebird');
var async = require('async');
var options = require('./options');
var mongoose = require('mongoose');

var ModelFactory = function () {

};

ModelFactory.prototype.make = function (name, schema) {
    function checkPreconditions(callback){
        if (!name) {
            return callback(new Error('name undefined'));
        }

        if (!schema) {
            return callback(new Error('schema undefined'));
        }

        if (!mongoose) {
            return callback(new Error('mongoose undefined'));
        }

        callback(null, schema);
    }

    function makeModelFromSchema(schema, callback){
        try {
            var model = mongoose.model(name, mongoose.Schema(schema, options));

            model.findOneAndUpdateWithOptimisticConcurrencyCheck = function (obj, callback) {
                obj.meta.versionId = (obj._version + 1).toString();
                model.findOneAndUpdate({_id: obj.id, _version: obj._version}, {$inc: {_version: 1}, $set: {meta: obj.meta, resource: obj.resource, index: obj.index}, $addToSet: {tags: { $each: obj.tags}}}, function (err, doc) {
                    if (err) return callback(err);
{'fraction_non_alphanumeric': 0.13555194805194806, 'fraction_numerical': 0.0016233766233766235, 'mean_word_length': 2.7864823348694316, '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': '5906110', 'n_tokens_mistral': 677, 'n_tokens_neox': 667, 'n_words': 173}