дискриминатор Мангуста 5.4.6 не появляется - PullRequest
0 голосов
/ 23 января 2019

Дискриминатор не отображается при сохранении унаследованного объекта, и я не могу найти причину его возникновения: Мангуст: 5.4.4, Узел: 11.6.0 Экспресс: 4.16.4

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const options = {
    discriminatorKey: 'kind'
};

const AlternativeSchema = new Schema({

    createdAt: {
        type: Date,
        default: Date.now
    },
    questionId: {
        type: Schema.Types.ObjectId,
        ref: 'Question',
        required: true
    },
    belief: {
        type: Number,
        required: true,
        default: 0
    },
    baserate: {
        type: Number,
        required: true
    }
},
options);

module.exports = mongoose.model('Alternative', AlternativeSchema);

// дочерний файл:

const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const Alternative = require('./alternative.js');


const SingletonSchema = new Schema({
    title: {
        type: String,
        default: 'compound',
        required: true
    },
    desc: {
        type: String
    }
});

module.exports = Alternative.discriminator('Singleton', SingletonSchema);

И когда я делаю следующее: const newSingleton = новый синглтон (...) newSingleton.save ();

Дискриминатор не сохраняется. Есть идеи, почему это было бы поведение?

...