我的数据长这样:
{
"name":"dan",
"somestring":"asdf",
"friends":[
{
"name": "carl",
"height":180,
...
},
{
"name": "john",
"height":165,
...
},
{
"name": "jim",
"height":170,
...
}
]
},
...
我想检索按身高降序排列的朋友名单文档。
我尝试了db.getCollection('users').find({"name" : "dan"}, {"friends" : 1}).sort({"friends.height" : -1})
,但朋友列表仍保持不变。
编辑:我弄错了数据结构,已经将数组修复为正确格式...