我有一个集合,其中我以下面的格式存储数据我想在下面的集合中应用排序。
{
"job_count" : [
ObjectId("58eb607531f78831a8894a3e"),
ObjectId("58eb607531f78831a8894a3e"),
ObjectId("58eb607531f78831a8894a3e")
]
},
{
"job_count" : [
ObjectId("58eb607531f78831a8894a3e")
]
},
{
"job_count" : [
ObjectId("58eb607531f78831a8894a3e"),
ObjectId("58eb607531f78831a8894a3e")
]
}
我希望数据如下所示
{
"job_count" : [
ObjectId("58eb607531f78831a8894a3e"),
ObjectId("58eb607531f78831a8894a3e"),
ObjectId("58eb607531f78831a8894a3e")
]
},
{
"job_count" : [
ObjectId("58eb607531f78831a8894a3e"),
ObjectId("58eb607531f78831a8894a3e")
]
},
{
"job_count" : [
ObjectId("58eb607531f78831a8894a3e")
]
}
我的完整查询是
Jobs.aggregate(
{"$match" : $condArray},
{"$unwind" : { path: "$mytradesmen.hired", preserveNullAndEmptyArrays: true}},
{"$lookup" : {
"from":"users",
"localField":"mytradesmen.hired",
"foreignField":"_id",
"as": "user_details"
}
},
{"$unwind": { path: "$user_details", preserveNullAndEmptyArrays: true}},
{ "$sort" : {"job_count":-1}})
任何人都可以帮我弄清楚我应该修改的查询以获得预期的结果, 如果需要进一步的详细信息,请告诉我,我会相应地编辑我的问题