我需要为下面嵌套的JSON数组创建一个Mongoose模型。我面临的问题是TLSM01是一个动态密钥,我无法在模型中指定它。如果我单独提及实体并将所有json对象作为字符串传递,则它将存储为[object]而不是数据。
"entities": [
{
"TLSM01": [
{
"01": {
"Name": "Light",
"Properties": [
{
"state": [
{
"type": "boolean",
"propertyMode": "actuator"
}
],
"brightness": [
{
"type": "integer",
"propertyMode": "actuator"
}
]
}
]
}
}
]
}
猫鼬模型:
var thingsSchema = ({
"uuid": String,
"things": String,
"manufacturerName": String,
"manufacturerId": String,
"osName": String,
"hardwareVersion": String,
"firmwareVersion": String,
"entity": [{String}]
})
答案 0 :(得分:0)
将数据存储在键值对
中var thingsSchema = ({
"uuid": String,
"things": String,
"manufacturerName": String,
"manufacturerId": String,
"osName": String,
"hardwareVersion": String,
"firmwareVersion": String,
"entity": [{_id:false,keyName:{type:String},data:[]}]
})
猫鼬模型:
php_admin_value[always_populate_raw_post_data] = -1