{
_id:123,
comment:[
{
Id: 1,
Score:0
},
{
Id: 3,
Score:1
},
{
Id: 4,
Score:0
}
{
Id: 7,
Score:21
}
]
}我現在需要實作查詢Score為0的comment,同時回傳新的結構,如下:
{
_id:123,
comment:[
Id: 1,
Score:0
},
{
Id: 4,
Score:0
}
]
}
uj5u.com熱心網友回復:
db.getCollection("comment").aggregate({ $project:
{ "comment": { $filter: { input: "$comment", as: "comment", cond: { $eq: [ '$$comment.Score', '0' ] } } } }
} )
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/85457.html
標籤:MongoDB
