简体   繁体   English

创建类型为 Array of Maps 的 Mongoose Schema

[英]Create a Mongoose Schema of type Array of Maps

I am trying to create a mongoose schema that is an array of Maps that are String -> String:我正在尝试创建一个猫鼬模式,它是一个字符串数组 -> 字符串:

var daySchema = new mongoose.Schema({
    schedule:  {
        type: [Map], 
        of: String
    }
});

This is what I have, but it's giving me a validation error.这就是我所拥有的,但它给了我一个验证错误。

How about creating a separate schema for the maps and then use that schema in an array:如何为地图创建一个单独的架构,然后在数组中使用该架构:

var Schedule = new mongoose.Schema({
    type: Map,
    of: String
});

var daySchema = new mongoose.Schema({
    type: [Schedule]
});

As shown in the array examples.数组示例所示。

You could do this:你可以这样做:

var daySchema = new mongoose.Schema({
    schedule:  {
        type: [{type: Map, of: String}], 
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM