在保存继承的对象时,不显示鉴别器,而且我似乎也找不到导致它的原因: 猫鼬: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 = new Singleton(...) newSingleton.save();
不保存鉴别符。 有什么想法为什么会这样吗?