繁体   English   中英

mongodb 找都慢

[英]mongodb find all slow

我是 nodejs 和 mongodb 的新手。 我有一个简单的请求,它将返回 800 个没有任何 where 语句的实体。 全部找出来。 或解释(); 回复太慢了。。。。。。

有没有更好的方法来做 collection.find().lean()?

const Jobs = require("../model/Jobs.mongo");

const saveData = async (title, link, location, idJob, companyName) => {
  const found = await Jobs.findOne({ idJob: idJob });
  if (!found) {
    try {
      const job = new Jobs({
        title: title,
        link: link,
        location: location,
        idJob: idJob,
        companyName: companyName,
      });
      await job.save();
      console.log(job);
    } catch (e) {
      console.log(e);
    }
  } else {
    console.log(`${title} ***** is already in the data with id ***** ${idJob}`);
  }
};

const getAllJobs = async (req, res) => {
  const jobs = await Jobs.find({}).sort({ createdAt: "desc" }).lean();
  res.status(200).json({ jobs, count: jobs.length });
};

const getJobByCompany = async (req, res) => {
  const {
    params: { companyName: companyName },
  } = req;

  const job = await Jobs.find({
    companyName: companyName,
  });
  if (!job) {
    res.status(404).json({});
  }
  res.status(200).json({ job, count: job.length });
};

module.exports = {
  saveData,
  getAllJobs,
  getJobByCompany,
};

如果您在一段时间内遇到此问题,请尝试检查您的互联网连接。

您还可以查看您想要接收的数据量。

可能只是因为互联网速度下降,让我知道结果是什么:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM