首页 > 解决方案 > 如何获取大型数据集上的查询结果总数?

问题描述

我收集了 1000 万个文档,我使用 atlas-search 中的 $search 运行查询,
我想显示结果的总数,但返回结果需要很长时间。

我试过这个: -

{
  '$search': {
    // index: 'default',
    'text': {
      'query': query,
      // path: {
      //   'wildcard': '*'
      // }
      'path': ['title', 'description']
    }
  },
},
// {
//   $count: "total"
// },
// {
//   $group:{_id: null,Total:{$sum:1}} 
//   } 
// {
//   $limit: 80
// },
// {
//  $facet:{"groupedByColors":[{$unwind: "$color"},{$group:{_id:"$color","count":{$sum:1}}},{$project: { "colorfield": "$_id", "count": 1 }},{$sort:{"count":-1}},{$limit: 10}]}
// }
// {
//   $facet:{"groupedByColors":[{$unwind: "$color"},{$group:{_id:"$color","count":{$sum:1}}},{$project: { "colorfield": "$_id", "count": 1 }},{$limit: 10}]}
//  }
]

标签: mongoosemongodb-queryaggregation-frameworkmongodb-atlas-search

解决方案


推荐阅读