在猫鼬混合/对象模式类型中设置所有属性的特定类型

时间:2019-02-15 09:19:16

标签: node.js mongodb mongoose

我正在用猫鼬设计一个问题模型,其中一个问题将包含4个或更多的词干。现在,我要创建一个茎对象,其所有属性都应为字符串类型和maxlength:200;如何在Mongoose模型中定义它? 我尝试了一些:

    stems:{
        type: String, // it give me a property of string type
        maxlength: 200
    }

    stems:{
        1: {
            type: String, // it works but suppose stem number may be 10 or more, 
            maxlength: 200
        },
        2: {
            type: String, 
            maxlength: 200
        }

    }

我想知道Mongoose中是否有任何方法来定义对象/混合类型,其中将包含带有某些规则(例如maxlength,minlength)的特定嵌套模式类型(例如字符串,数字),但是我没有定义密钥/属性。如:

    stems{
        type: Object,
        allNestedElement: {
           type: String,
           maxlength: 200 
        }
    }

0 个答案:

没有答案