0
我有以下數據
[
{
"_id": "58fb3b7b78352e228c9e86b5",
"item_id": "xxxxx",
"sku": "D7C-670-A7B",
"price": "40.73",
"categoryname": "TV, film e videogiochi",
"categoryid": 75708,
"__v": 0,
"country": "Italy",
"specifics": {
"NameValueList": [
{
"Name": "MPN",
"Value": "Does Not Apply",
"Source": "ItemSpecific"
},
{
"Name": "EAN",
"Value": "Non applicabile",
"Source": "ItemSpecific"
},
{
"Name": "EAN",
"Value": "Non applicabile"
},
{
"Name": "ISBN",
"Value": "Non applicabile"
}
]
},
"ean": "Non applicabile"
},
{
"_id": "58fb3b7b78352e228c9e86b7",
"price": "13.6",
"categoryname": "Etuis, housses, coques",
"categoryid": 20349,
"__v": 0,
"country": "France",
"specifics": {
"NameValueList": [
{
"Name": "Compatible Marques",
"Value": "Pour Samsung, Apple, pour HTC, pour LG, pour Google",
"Source": "ItemSpecific"
},
{
"Name": "Compatible Modèles",
"Value": "iPhone 5, 5S,5C,6,6S",
"Source": "ItemSpecific"
},
{
"Name": "Design/Finition",
"Value": "Brillant et Mat",
"Source": "ItemSpecific"
},
{
"Name": "Caractéristiques",
"Value": "Étanche, Étui Rigide",
"Source": "ItemSpecific"
},
{
"Name": "MPN",
"Value": "Elephant",
"Source": "ItemSpecific"
},
{
"Name": "Matériau Du Produit",
"Value": "Polycarbonate Plastique",
"Source": "ItemSpecific"
},
{
"Name": "Type :",
"Value": "Fitted Case/Skin",
"Source": "ItemSpecific"
},
{
"Name": "Numéro de pièce fabricant",
"Value": "Elephant",
"Source": "ItemSpecific"
}
]
},
"ean": ""
}]
我希望得到所有具有
spicifics.NameValueList.Name = "MPN" && spicifics.NameValueList.Name = "Universal"
我使用$放鬆身心$彙總查詢,但它沒有返回的項目中,預期產出。
ebayItems.aggregate([
{$unwind:'$specifics.NameValueList'},
{
$group:{"_id":"$item_id"}
},
{$project:{"_id":1,"HasMPN":{"$cond":{
"if":{"$eq":["$specifics.NameValueList.Name","MPN"]},
"then":"HasMPN",
"else":"NoMPN"
}}}}
]).exec(function(err,item){
if (err) {
res.json(err)
} else {
res.json(item)
}
})
上面的輸出總是'NoMPN'。上面兩個字段的預期輸出應該是'HasMPN'。
感謝其對我的作品,但我需要在那裏spicifics.NameValueList.Name =「 MPN「&& spicifics.NameValueList.Name =」Universal「 –
歡迎您。那就是我所擁有的'{「specifics.NameValueList.Name」:{$ all:[「MPN」,「Universal」]}}'。你能提供一個例子嗎?更多https://docs.mongodb.com/manual/reference/operator/query/all/#equivalent-to-and-operation – Veeram
對不起,當我運行你的查詢時,它所做的是單獨找到MPN和Universal,它應該只找到{ 「名稱」: 「MPN」, 「值」: 「通用」, 「源」: 「ItemSpecific」 } –