MongoClient.connect is very slow online, but very fast locally, looking for a solution.

when node.js connects to mongodb and executes MongoClient.connect (), it is very fast in the local environment, but very slow to get online, which takes more than 1 second, as shown below:

var express = require("express");
var router = express.Router();
var MongoClient = require("mongodb").MongoClient;
var url = "mongodb://localhost:27017/";
var tools = require("../../public/tools/tools")

/* GET home page. */
router.get("/", function(req, res) {
  //
  console.time("find")
  MongoClient.connect(url, {useNewUrlParser:true},function(err, db) {
    console.timeEnd("find") //
    if (err) throw err;
    var dbo = db.db("qianyanjiu");
    var mysort = { postdate: -1 };
    where = {status: 1}
    dbo.collection("news").find(where).sort(mysort).limit(5).toArray(function(err, result) {
        if (err) throw err;
        
        for(var i = 0; i < result.length; iPP){
          result[i].postdate = tools.getDate(result[i].postdate)
        }
        db.close();
        res.render("web/index", { 
          news:result
        });
    });
  });  
});

the speeds are as follows:

clipboard.png

clipboard.png

one needs more than 1s, one only needs 10ms, and the other needs to load more than 1s online to display the web page.

ps: the server is an Ali Cloud single-core 2g efficient cloud disk, and the local i7 16g ssd is related to the configuration.

May.24,2022

I wrote it incorrectly

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b30bd1-2bd67.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b30bd1-2bd67.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?