我的MongoDB存储具有以下结构的文档:
{
"application_detail":{},
"curl_detail":{
"Curl1":{
"key1":"value1",
"key2":"value2"
},
"Curl2":{
"key1":"value1",
"key2":"value2"
},
"Curl3":{
"key1":"value1",
"key2":"value2"
},
"Curl4":{
"key1":"value1",
"key2":"value2"
},
/*total number of curls are unknown*/
}
}
现在,我正在使用猫鼬为key1
中存在的每个Curl仅获取curl_detail
的值。
如何为此类文档定义架构?
答案 0 :(得分:1)
您可以使用Map schema type:
const schema = new mongoose.Schema({
curl_detail: {
type: mongoose.Schema.Types.Map,
of: {
key1: String,
key2: String
}
}
})