The performance of Mongoose queries is lagging, regardless of using lean

Utilizing MongoDB for data storage and Mongoose in Express for handling modifications, I believe my query processes should be optimized for speed. Correct me if I'm mistaken, but the dataset is large yet not overwhelmingly huge, especially since there are no filtering operations during the query.

The model schema I employ:

const DataSchema = mongoose.Schema({
  title: String,
  text: String,
  text_transform: Array,
  provider: String,
  url: {
    type: String,
    unique: true,
  },
  word_count: Array,
  HOW: Array,
  date: Date,
  click_count: Number,
}); 

A few key points to note:
text field can vary in size from 150 to potentially over 7000 characters.
text_transform is an array containing words from the text field.
provider is a short string with maximum length of 12 characters.
word_count contains key-value pairs represented as arrays within the array like this:

[
   ["key", value], ["other_key", other_value], ...
]

The values are numbers while the keys are strings.
HOW is an array with at most 5 elements, each element being a string ranging from 6-10 characters.

Upon triggering a query from my own API endpoint, I encounter challenges when trying to retrieve all the data.

My request goes to this endpoint:

router.get("/", async (req, res) => {
  try {
    const data = await DataSchema.find({}).lean();
    res.json(data);
  } catch (err) {
    res.status(404);
  }
});

As evident, I utilize lean() method for simplicity and return a JSON response. However, querying on the client side revealed sluggish performance even with around 270 documents in the database.

I suspect it's not a network issue because limiting the query to the first 10 elements results in noticeable improvement but still slower than anticipated, taking roughly a second.

Are there optimization methods to expedite this process?

In addition, it's worth noting that for development purposes, I am using the free tier of MongoDB Atlas without access to profilers or performance analytics. Also, lacking a production environment for testing and opting for Belgium region (europe-west1) due to proximity factors.

Furthermore, I conducted tests by removing text_transform field temporarily, yielding minimal impact on query speed.

EDIT:

Remembering to mention, I implemented an endpoint returning hardcoded JSON under 1 ms processing time, emphasizing the perceived slowness solely during queries.

.explain() outcomes

[
  {
    queryPlanner: {
      plannerVersion: 1,
      namespace: 'test.articles',
      indexFilterSet: false,
      parsedQuery: {},
      winningPlan: [Object],
      rejectedPlans: []
    },
    executionStats: {
      executionSuccess: true,
      nReturned: 301,
      executionTimeMillis: 0,
      totalKeysExamined: 0,
      totalDocsExamined: 301,
      executionStages: [Object],
      allPlansExecution: []
    },
    serverInfo: {
      host: 'some.database-shard.mongodb.net',
      port: 27017,
      version: '4.2.6',
      gitVersion: '20364840b8f1af16917e4c23c1b5f5efd8b352f8'
    },
    ok: 1,
    '$clusterTime': { clusterTime: '6831457389108002820', signature: [Object] },
    operationTime: '6831457389108002820'
  }
]

Thank you for your time and assistance in advance.

Answer №1

If you're facing a similar issue, I recently discovered that the culprit was MongoDB Atlas.

It seems that while MongoDB Atlas processed the query quickly, it struggled to deliver the results promptly, possibly due to overload on shared servers in the free M0-sandbox package. While I can't say for certain, this experience is reassuring in a production setting where such delays shouldn't be tolerated.

In summary:

I've since switched to another free mongodb provider for development, and now everything loads almost instantly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Validation in AngularJS - Setting minimum length for textarea using ng-minlength

I am currently tackling a project that heavily relies on AngularJS for the front-end. Here's what I am dealing with: The validation requirement I am aiming for is as follows: The Next button should remain disabled unless the reason provided is at le ...

The JavaScript functions are not loading within the onload event handler

I've got an HTML document that contains some Script sections. I've consolidated all the functions within a single Script Tag. Now, I want to be able to utilize these methods in both the onload and onclick events. Below is the HTML file with all t ...

Expanding jQuery Accordion on clicking a link within the panel

I have implemented an accordion feature on my webpage and I am looking to include hyperlinked text within each expanded panel. By clicking on the link 'Reduce text', I want to be able to collapse the accordion. How can I modify the existing code ...

Tips for altering dual data values in Vue

When working with Vue.JS, I encounter the following situation: data() { return { name: 'John', sentence: "Hi, my name is {{ name }}", }; }, In my HTML file, I have the following line: <h2>{{ sentence}}</h2> ...

Search for items in a collection with Spring's CrudRepository while ignoring case sensitivity

After looking at the syntax for various query types, I thought the syntax for an ignore case query would be: findByFieldIgnoreCase(Object field) Then, based on the syntax for a collection query: findByFieldIn(List<Object> fields) I assumed the sy ...

Is the Jade template engine becoming obsolete with the use of the AngularJS framework?

As someone just starting out in MEAN stack/web/mobile development, I've noticed that AngularJs is capable of handling all the client-side templating and generating dynamic content. So why do developers still opt to use Jade for server-side templating? ...

The functionality of scope.$observe is unavailable within an AngularJS Directive

Consider the snippet below: appDirectives.directive('drFadeHighlight', ['$animate', '$timeout', function ($animate, $timeout) { return { scope: { isWatchObject: '=' }, restric ...

The command 'w' is not acknowledged as a valid internal or external command, executable program, or batch file

$ heroku config:set MONGODB_URI="my url"; At the end of my MongoDB Atlas URL, there is a query string "?retryWrites=true&w=majority" However, when trying to set this configuration in Heroku, I am encountering an error message saying 'w' is ...

Tips for storing and recalling a 24-hour countdown timer using Local Storage

I'm new to JavaScript and I have a 24-hour countdown timer that resets on page reload. However, I want to use LocalStorage to save the starting progress so that it continues running even if the page is closed or refreshed. The goal is for the timer to ...

Error: Reading the property 'any' of an undefined object resulted in a TypeError after an update operation

After updating multiple npm packages in my application, I encountered a series of errors that I managed to resolve, except for one persistent issue! TypeError: Cannot read property 'any' of undefined at Object.<anonymous> (/home/cpt/Deskto ...

Encountered ENOENT error while setting up create-react-app

Recently delved into the world of React by taking an online course on Udemy. However, I encountered a sudden issue with my create-react-app and received this error log. Installing packages. This may take a few minutes. Installing react, react-dom, and ...

Looking to transform an HTML table into a stylish CSS layout complete with a form submission button?

Recently, I've been delving into the world of CSS and PHP as I work on converting old code entirely into HTML and PHP with a touch of CSS. The visual aspect seems fine, but I've hit a roadblock with the submit form due to an IF statement in PHP. ...

Having trouble getting socket io to show any emits on the screen

I've been troubleshooting why my terminal isn't displaying any emits, even though everything seems to be running smoothly. Below is the code snippet I'm working with: var express = require('express'); var path = require(&a ...

Creating flexible padding for child elements inside a container using CSS

I am facing a challenge in creating dynamic padding within a container. Consider the following HTML: <div class="sections-container"> <div class="section"> </div> <div class="section"> </div> </div> and the corres ...

Issues encountered when implementing dynamic routing with ExpressJs and handling React GET requests

I'm facing an issue with my simple API and client application setup. The API is written using Express.js and the client-side utilizes React. I have successfully implemented dynamic routing in React, but when attempting to send a GET request to an endp ...

A guide on implementing a TypoError in Node.Js and Discord.Js for enabling a bot to enter a voice channel

Hello there, I'm currently working on a music Bot for Discord using Javascript with Node.Js and I've encountered an issue: This problem arises specifically with the "play" command, but it seems to occur with all commands that involve joining a v ...

Automatically update the border sample once the visitor enters a color code into the input text field

Is it possible to automatically change the sample border when a visitor enters a color code in the input textfield at: Do you have a specific border color in mind? input name="ContentInclude:borderspecs" type="text" maxlength="200" id="ContentInclude_bor ...

The CSS cursor style is taking precedence over the inline cursor style while dragging items in the list

I am currently utilizing the Nestable JS library and have a list of nestable items in my tree. I am trying to implement a cursor: pointer when hovering over them and a cursor: move when dragging. However, I am facing issues in getting this functionality to ...

Modify the class of the dropdown and heading 2 elements if they meet specific conditions using Animate.css

Is it possible to add a class using jQuery when two specific conditions are met? 1) If the dropdown selection is either "acting" or "backstage" 2) If the membership status is set to "Non-member" If both of these requirements are fulfilled, I would like ...

Troubleshooting: How can I ensure my custom scrollbar updates when jQuery niceselect expands?

I am currently utilizing the jquery plugins mCustomScrollbar and niceselect. However, I have encountered an issue when expanding the niceselect dropdown by clicking on it - the mCustomScrollbar does not update accordingly. I suspect this is due to the abso ...