Query on small collection is fast using Postman and very slow within my NodeJS app

I have a node js app using mongoosejs that accesses a db in a serverless instance. I want to query a collection that contains 204 documents. The mongoose code is:

const result = await Listing.find({}).lean()

The query is taking 7 to 10 seconds to complete.

If I run the same query inside a Postman call to the Atlas API, it completes in 1 second. Both my nodejs app and Postman are running on my local computer so hardware and network is the same.

Here’s the Postman call:

Does anyone know what is happening and how I can improve the mongoose/nodejs performance?

Hey @Steven_Manus,

Welcome to the MongoDB Community forums!

Could you please provide the code snippet you are executing, along with the sample documents? Additionally, could you share the Node.js version, the Mongoose version you are using, and the hardware specifications of your system?

Also, please share how you determine the query time in the case of your Node.js application. This will provide the community with additional information to better assist you.

Best regards,

Thanks Kushagra. I’ve created a minimal version of the site for testing. Here’s part of my VSC screen showing the code snippet and Terminal showing timings of 5 sequential loads of the home page.

I’m running node 18.18.0 and mongoose 8.0.2 on a Macbook M1 Pro with 16GB of memory running Sonoma 14.1.1.

Not sure what you mean by sample documents but here’s a screenshot from Atlas of the colleciton:

The full schema is:

const listingSchema = new mongoose.Schema({
shortTitle: String,
etsyTitle: String,
description: String,
etsyId: Number,
state: String,
etsyShopSectionId: Number,
categories: [{type: Schema.Types.ObjectId, ref: “Category”}],
collections: [{type: Schema.Types.ObjectId, ref: “Collection”}],
imageUrls: [{rank: Number, url: String, thumbnail: String}],
videoUrls: [{height: Number, width: Number, url: String}],
sizes: [{size: String, imageUrl: String}],
colors: [{color: String, imageUrl: String}],
styles: [{category: String, styles: [{value: String, imageUrl: String}]}],
price: Number,
etsyRank: Number,
etsyUrl: String,
customizable: Boolean,
personalizable: Boolean,
personalizationRequired: Boolean,
personalizationCharCount: Number,
personalizationInstructions: String,
tags: [String],
materials: [String],
processingMin: Number,
processingMax: Number,
etsyPartners: [Number],
partners: [{type: Schema.Types.ObjectId, ref: “Partner”}],
originIso: String,
originPostalCode: String,
shippingDestinations: [
{region: String,
iso: String,
priceBreaks: [
{breakQty: Number,
amount: Number,
currency: String
minDays: Number,
maxDays: Number
}, opts);

BTW - I ported my database to my local machine and tested there. Query times were around 90ms so I think this confirms that the problem is between nodejs/mongoose and Atlas.