如何在猫鼬模式中设置数组对象的默认值?

问题描述

我为此尝试了许多方法。我还找不到正确的方法。请查看收藏夹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,//Custom part
        customImplantOrganization: {
            type: String,enum: ['A','B','C'],customImplantType: {
            type: String,enum: ['D','F'],customImplantSize: {
            type: String,enum: ['E','Q'],customHexOption: {
            type: String,enum: ['P'],customProcessManner: {
            type: String,enum: ['7','6'],customOption: {
            type: String,enum: ['2','3','4'],//Crown part
        crownShade: {
            type: String,enum: ['91'],default: [null],crownStrength: {
            type: String,'78'],crownoption: {
            type: String,enum: ['9'],default: undefined,wasCreated: {
            type: Boolean,default: false,modifiedBy: {
        type: String,modifiedTime: {
        type: Date,default: null
    },});
module.exports = mongoose.model('memberSetting',MemberSettingSchema);

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)