node.js - 如何使用 Mongodb 和 Node 优化 .find .count 查询?
问题描述
我创建了一个 API 来获取使用 Mongodb 和 Node.js 的文档数。
查询是
var searchquery = 'ABC';
let regexexp = new RegExp(searchquery.split('').join('\\s*'),'i');
s = {"name": regexexp, "status": 'AVAILABLE'};
db.collection(collectionName).find(s).count().then(function(totalcount) {
console.log(totalcount);
});
从 6000 万条记录中获取计数结果大约需要 1 分钟。如何在 1-2 秒左右的最短时间内获取该数据。
有什么我错过或使用错误的吗?
解决方案
推荐阅读
- amazon-web-services - 在 AWS 放大中设置烧瓶后端
- ruby-on-rails - rails: Link_to 查找方法
- javascript - 如何在 jquery 中使问题测验中的其他选项不可点击
- python - 如果 render_to_response 方法没有包含在任何地方,为什么我会收到 ImportError?
- python - Python 3.8 TypeError: can't concat str to bytes - TypeError: a bytes-like object is required, not 'str'
- mongodb - 在批量操作中将匿名对象数组重组为 mongo 中的命名键对象
- java - Android:如何启动一个从下一个 2 秒的精确倍数开始的计时器?
- oracle - 未找到 PL/SQL 过程的参数名称,仅在 IIS7(非 IIS6)中
- javascript - mousemove 在控制台打开时更频繁地触发?
- android - 如何保持 firebase 实时数据库与 firebase 存储同步,这是解决两个嵌套查询问题的标准方法?