首页 > 解决方案 > 如何使用 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 秒左右的最短时间内获取该数据。

有什么我错过或使用错误的吗?

标签: node.jsmongodbperformanceoptimizationfind

解决方案


推荐阅读