[英]In MongoDb is there a way to get last 1000 array elements from multiple documents
您是否看过Mongo聚合? 如果您想返回1000个最新的摘要,可以使用$ unwind和$ replaceRoot操作,这是我尝试过的shell查询:
db.getCollection('test').aggregate([
{$match : {your timestamp match query here}},
{$sort : {"timestamp": -1}},
{$unwind : "$summaries"},
{$limit : 1000},
{$replaceRoot: {newRoot: "$summaries"}}
])
聚合管道开始处的match操作非常重要,因为仅在第一步使用索引。 如果您放松整个收藏,您的表现可能会急剧下降。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.