我为此尝试了许多方法。我还找不到正确的方法。请查看收藏夹array
对象和默认值。当我保存它时,数组对象的一部分不包含null
对象。
const mongoose = require('mongoose');
const MemberSettingSchema = new mongoose.Schema({
organization: {
type: String,
unique: true,
required: true,
},
favorites: {
type: Array,
validate: {
validator: function() {
return this.favorites.length <= 20;
},
message: 'Array exceeds max size.'
},
name: {
type: String,
default: null,
required: true,
},
//Custom part
customImplantOrganization: {
type: String,
required: true,
enum: ['A', 'B', 'C'],
default: null,
},
customImplantType: {
type: String,
enum: ['D', 'F'],
default: null,
},
customImplantSize: {
type: String,
enum: ['E', 'Q'],
default: null,
},
customHexOption: {
type: String,
enum: ['P'],
default: null,
},
customProcessManner: {
type: String,
enum: ['7', '6'],
default: null,
},
customOption: {
type: String,
enum: ['2', '3', '4'],
default: null,
},
//Crown part
crownShade: {
type: String,
enum: ['91'],
default: [null],
},
crownStrength: {
type: String,
enum: ['7', '78'],
default: null,
},
crownOption: {
type: String,
enum: ['9'],
default: undefined,
},
wasCreated: {
type: Boolean,
default: false,
},
},
modifiedBy: {
type: String,
default: null,
},
modifiedTime: {
type: Date,
default: null
},
});
module.exports = mongoose.model('memberSetting', MemberSettingSchema);