0
MongoDB的小白在這裏打最小結果...如何在MongoDB中
所以,我想打印出一個集合,看起來像這裏面的最小值得分...
> db.students.find({'_id': 1}).pretty()
{
"_id" : 1,
"name" : "Aurelia Menendez",
"scores" : [
{
"type" : "exam",
"score" : 60.06045071030959
},
{
"type" : "quiz",
"score" : 52.79790691903873
},
{
"type" : "homework",
"score" : 71.76133439165544
},
{
"type" : "homework",
"score" : 34.85718117893772
}
]
}
我使用的咒術這樣...
db.students.aggregate(
// Initial document match (uses index, if a suitable one is available)
{ $match: {
_id : 1
}},
// Expand the scores array into a stream of documents
{ $unwind: '$scores' },
// Filter to 'homework' scores
{ $match: {
'scores.type': 'homework'
}},
// grab the minimum value score
{ $match: {
'scores.min.score': 1
}}
)
我得到的輸出是這樣的......
{ "result" : [ ], "ok" : 1 }
我在做什麼錯?
我相信你想在這裏使用'$ min': http://docs.mongodb.org/manual/ reference/aggregation /#_ S_min – Sammaye
我是... {$ match:{ 'scores.min.score':1 }} – thefonso