esty
esty

Reputation: 73

How to make mongodb and nodejs response fast?

I have a blog schema(title, topic, body, author, etc) and a function to return all the blogs in that document. Right now I am just doing Blog.find() to pull all the data at once and sending the responses using res.send(). The problem is the body property of the blog is very large and it takes a lot of time to return the results. Is there any way to make it fast.

Upvotes: 1

Views: 128

Answers (1)

Murat Colyaran
Murat Colyaran

Reputation: 2189

You can get faster results if you add the fields you use the most in searches to the collection as an index.

Usage example:

//The following example creates a single key descending index on the name field:
db.collection.createIndex( { name: -1 } )

Upvotes: 1

Related Questions