简体   繁体   English

mongodb 找都慢

[英]mongodb find all slow

I'm new with nodejs and mongodb.我是 nodejs 和 mongodb 的新手。 I have a simple request which will return 800 entities without any where statements.我有一个简单的请求,它将返回 800 个没有任何 where 语句的实体。 Just find all.全部找出来。 or explain();或解释(); Very slow responder.....回复太慢了。。。。。。

Is there a more better way to do collection.find().lean()?有没有更好的方法来做 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,
};

If you are facing this issue for a while try to check you internet connection.如果您在一段时间内遇到此问题,请尝试检查您的互联网连接。

You can also take a look how much is the data that you want to receive.您还可以查看您想要接收的数据量。

It can be just from a internet speed drop, let me know what is the result:)可能只是因为互联网速度下降,让我知道结果是什么:)

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

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