我有一個內部包含產品(對象)的數組。它看起來像:我應該怎麼做一個聚合?
[
{_id: 123, name:'first', category:'Vape', property:[
{key:'brand', values:'Eleaf'},
{key:'mechmode', values:'some'},
{key:'color', values:['red', 'blue']},
{key:'batrtype', values:'some2'},
]},
{_id: 1234, name:'second', category:'Vape1', property:[
{key:'brand', values:'Eleaf1'},
{key:'mechmode', values:'some'},
{key:'color', values:['black']},
{key:'batrtype', values:'some2'}
]},
{_id: 12345, name:'third', category:'Vape3', property:[
{key:'brand', values:'Eleaf3'},
{key:'mechmode', values:'some'},
{key:'color', values:['green', 'yellow']},
{key:'batrtype', values:'some2'}
]},
{_id: 123456, name:'fourth', category:'Vape', property:[
{key:'brand', values:'Eleaf'},
{key:'mechmode', values:'some'},
{key:'color', values:['red', 'green']},
{key:'batrtype', values:'some2'}
]}
]
從客戶
{category:'Vape', body:{brand:'Eleaf', color:'red'}}
請求我應該怎麼做蒙戈合計獲得具有品牌=「Eleaf」 和顏色的產品=紅色根據要求?
有人可以幫忙嗎?
該數組是作爲單個字段存儲在文檔中的,還是集合中的文檔列表? – Joe
它是集合中的文檔列表 –