我有这个查询:
[
{
'$match': {
'imageUrls': {
'$type': 'array',
'$ne': []
}
}
}, {
'$project': {
'imageUrls': 1,
'time': 1
}
}, {
'$sort': {
'time': 1
}
}, {
'$skip': 0
}, {
'$limit': 10
}
]
这是模式:
{
"_id": {
"$oid": "5ffb0c14dd482daa039ee906"
},
"imageUrls": ["image url1", "image url2"],
"time": 342432432432
}
输出是文档列表,每个文档包含array字段imageUrls
。我想将所有值都imageUrls
放在一个数组字段中。
$sort
按时间降序排列$project
只显示一个字段 imageUrls
$unwind
解构imageUrls
数组$facet
分开结果,总计和分页文件$skip
单据$limit
文件数量$group
通过null
并重建imageUrls
数组 { $sort: { time: -1 } },
{ $project: { imageUrls: 1 } },
{ $unwind: "$imageUrls" },
{
$facet: {
result: [
{ $skip: 0 },
{ $limit: 10 },
{
$group: {
_id: null,
imageUrls: { $push: "$imageUrls" }
}
}
],
count: [
{ $count: "count" }
]
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句