我有一个如下所示的模式。
var menuDetail = mongoose.Schema({
menu_detail :[{ //1st level
level : String,
menu : [{//2nd level
menu_category : String, //
menuItem:[{//3rd level
menu_name : String,// Queens lick, spaghetti cake mix, burger, geentrumes, pizza
ingredients :[{//4th level
ingredient : String,
minimum_time : Number, // 5th level
taste_preference : String,//
taste_success : String,//
average_time : String,//
maximum_time : Number
}]
}]
}],
premium_menu:[{//2nd level
name : String, //Queens lick, spaghetti cake mix,
menu_item_code : String
}],
classic_menu:[{
name :String,//burger,pizza
menu_item_code : String
}]
}]
})
当我使用
model.find({ query })
.select( premium_menu.name premium_menu.menu_item_code
classic_menu.name classic_menu.menu_item_code )
它为我提供了以下示例
[{"_id":"5adf986959a97c2d94a299b2","menu_detail":[
{"premium_menu":[
{"name":"Queens lick","menu_item_code":"qnslck"},
{"name":"spaghetti cake","menu_item_code":"spagcake"}],
"classic_menu":[
{"name":"Burger","menu_item_code":"burg"},
{"name":"Pizza","menu_item_code":"pizz"}]}]}]
高级和经典项目都位于内部
menu.menu_item.menu_name i.e.
menu
menu_item
menu_name
但是我想将其链接到同一集合的另一部分,其中
menu.menu_item.menu_name i.e.
menu
menu_item
menu_name
结果将是 例如在
中找到Queens舔的地方menu.menu_item.menu_name i.e.
menu
menu_item
menu_name
获取最小时间和最大时间,结果看起来像这样
[{"_id":"5adf986959a97c2d94a299b2","menu_detail":[
{"premium_menu":[
{"name":"Queens lick","menu_item_code":"qnslck(min_time/max_time)"},
{"name":"spaghetti cake","menu_item_code":"spagcake(15/25)"}],
"classic_menu":[
{"name":"Burger","menu_item_code":"burg(30/45)"},
{"name":"Pizza","menu_item_code":"pizz(30/43)"}]}]}]