0
我有一個集合的命令,裏面收集我有屬性陣列,我想小組attributes.value其中attributes.name是「sugery」MongoDB中查詢到陣列
db.orders.find({},{"attributes":1}).sort({_id:-1}).limit(3);
{
"_id" : ObjectId("599cfdb0f6ec8d00015b0880"),
"attributes" : [
{
"id" : ObjectId("5979a220ad86210001997d5a"),
"name" : "patient",
"status" : NumberInt(1),
"sysDefined" : NumberInt(1),
"value" : "Lincon Burrows"
},
{
"id" : ObjectId("5979a229ad86210001997d5c"),
"name" : "notes",
"status" : NumberInt(1),
"sysDefined" : NumberInt(1),
"value" : ""
},
{
"id" : ObjectId("5979a230ad86210001997d5e"),
"name" : "surgeon",
"status" : NumberInt(1),
"sysDefined" : NumberInt(1),
"value" : "Dr. Williams"
},
{
"id" : ObjectId("5979a238ad86210001997d60"),
"name" : "surgery",
"status" : NumberInt(1),
"sysDefined" : NumberInt(1),
"value" : "Heart Surgery"
}
]
}
{
"_id" : ObjectId("599c357a9ec26c00017892a6"),
"attributes" : [
{
"value" : "new patient",
"sysDefined" : NumberInt(1),
"status" : NumberInt(1),
"name" : "patient",
"id" : ObjectId("5979a220ad86210001997d5a")
},
{
"value" : "",
"sysDefined" : NumberInt(1),
"status" : NumberInt(1),
"name" : "notes",
"id" : ObjectId("5979a229ad86210001997d5c")
},
{
"value" : "http://localhost:4200/#new surgeon",
"sysDefined" : NumberInt(1),
"status" : NumberInt(1),
"name" : "surgeon",
"id" : ObjectId("5979a230ad86210001997d5e")
},
{
"value" : "new surgery",
"sysDefined" : NumberInt(1),
"status" : NumberInt(1),
"name" : "surgery",
"id" : ObjectId("5979a238ad86210001997d60")
}
]
}
{
"_id" : ObjectId("599c2069b2afd900019ea142"),
"attributes" : [
{
"value" : "Mellisa Darwin",
"sysDefined" : NumberInt(1),
"status" : NumberInt(1),
"name" : "patient",
"id" : ObjectId("5979a220ad86210001997d5a")
},
{
"value" : "",
"sysDefined" : NumberInt(1),
"status" : NumberInt(1),
"name" : "notes",
"id" : ObjectId("5979a229ad86210001997d5c")
},
{
"value" : "Dr. Josefina P. Robles",
"sysDefined" : NumberInt(1),
"status" : NumberInt(1),
"name" : "surgeon",
"id" : ObjectId("5979a230ad86210001997d5e")
},
{
"value" : "Spine Surgery",
"sysDefined" : NumberInt(1),
"status" : NumberInt(1),
"name" : "surgery",
"id" : ObjectId("5979a238ad86210001997d60")
}
]
}
記錄
我想輸出像
[
{
"_id":"Heart Surgery",
"count":1
},
{
"_id":"new surgery",
"count":1
},
{
"_id":"Spine Surgery",
"count":1
}
]
雖然此鏈接可以回答這個問題,最好是在這裏有答案的主要部件,並提供鏈接以供參考。如果鏈接頁面更改,則僅鏈接答案可能會失效。 - [來自評論](/評論/低質量帖/ 17117743) –
@Szymon Stepniak謝謝你的意見 –