mongoose - 如何获取大型数据集上的查询结果总数?
问题描述
我收集了 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}]}
// }
]
解决方案
推荐阅读
- terraform - 如何在 terraform 中使用代码管道设置代码构建?
- c - 执行重定向到哪个文件描述符?
- python - 当我定义它时没有定义变量?
- java - 如何使用 Android 连接到内部存储中的 sqlite 数据库文件?
- c++ - 单击 QFrame 时出现段错误
- reactjs - 为网站上的每个视频链接创建 Opengraph 元标记?
- tensorflow - 使用多个 GPU 时的 TF Keras NAN 损失
- bash - 忽略 GitLab CI 管道脚本中的某些退出代码
- javascript - Discord.js TypeError:无法读取未定义的属性“电子邮件”
- python - 无法解决 ModuleNotFoundError:没有名为“sympy”的模块