[英]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.