# Netlify lambda & MongoDB time out

**URL:** <https://answers.netlify.com/t/netlify-lambda-mongodb-time-out/12395>\
**Category:** Support\
**Tags:** lambda-functions, deployment\
**Created:** [April 14, 2020, 3:05pm UTC](https://answers.netlify.com/t/netlify-lambda-mongodb-time-out/12395 "2020-04-14T15:05:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrewing](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/andrewing/32/9119_2.png) [@andrewing](https://answers.netlify.com/u/andrewing)\
**Post date:** [April 14, 2020, 3:05pm UTC](https://answers.netlify.com/t/netlify-lambda-mongodb-time-out/12395/1 "2020-04-14T15:05:40Z")

</div>

Hello!

I am quite new to Netlify. I am having a problem with MongoDB (specifically with atlas DB) and functions. Whenever I make a request to an endpoint that accesses the database, it times out after 10 seconds. This was not a problem when I was developing/testing it locally. I am aware that this is the maximum for functions level 0. I have also set the whitelisted IP to 0.0.0.0. Other functions that do not use/access the database work just fine. I just wanted to confirm whether the starting connection just takes a long time or something might be wrong with my code.

Thank you!

---

<div class="post-metadata">

**Author:** ![jen](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/jen/32/6044_2.png) [@jen](https://answers.netlify.com/u/jen)\
**Post date:** [April 16, 2020, 10:39pm UTC](https://answers.netlify.com/t/netlify-lambda-mongodb-time-out/12395/2 "2020-04-16T22:39:00Z")

</div>

Hey @andrewing!  
It’s very possible that your function is not able to complete its work in 10 seconds, or it needs more memory than [is available](https://answers.netlify.com/t/common-issue-functions-101-debugging/347).

> **Functions timeout after 10 seconds, and are limited to 1024mb (1 gb) of memory by default.** They are deployed to AWS Lambda in their `us-east-1` region. Some modules, for example, [Headless Chrome](https://developers.google.com/web/updates/2017/04/headless-chrome), require the whole 1gb of RAM! There are custom settings available (up to 26 seconds runtime and 3Gb memory) which you’ll need to contact our support team - please post in the #Admin area of this forum to get our attention for this.

Can you check your function logs and see if there’s any information there about duration or memory usage? Those will be here:

> **[Netlify App](https://app.netlify.com/sites/YOUR-SITE/functions)**
>
> Start building the best web experiences in record time

Also wanted to share this post on MongoDB in case it’s helpful for you:

> [@Fetching mongoDB data with lambda functions](https://answers.netlify.com/t/fetching-mongodb-data-with-lambda-functions/11225):
>
> I’m having an issue fetching mongoDB data using lambda functions when not working locally. I set up a sample mongodb filled with their sample data and simply want to pull it to be used on my website. When I work locally via the netlify-cli I am able to properly query the database and return the value I’m looking for without error. It’s when I push the function up to my site that I begin to run into issues with it timing out. My code can be seen below (username and pw changed) /\* eslint-disabl…

---

<div class="post-metadata">

**Author:** ![italodeandra](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/italodeandra/32/14117_2.png) [@italodeandra](https://answers.netlify.com/u/italodeandra)\
**Post date:** [August 2, 2020, 7:19pm UTC](https://answers.netlify.com/t/netlify-lambda-mongodb-time-out/12395/3 "2020-08-02T19:19:19Z")

</div>

As I mentioned in the [post](https://answers.netlify.com/t/fetching-mongodb-data-with-lambda-functions/11225) mentioned by @jen, for anyone who might come to this post after having problems with the timeout from the Netlify Functions while using MongoDB integration (I’m also using a Free server from MongoDB Atlas):

Create indexes. MongoDB might take some time (more than 10 seconds) to look for a simple string with a collection with 5 documents and an index will fix that.

If you’re using MongoDB Atlas, check this link to learn how to create index using the data explorer: [https://docs.atlas.mongodb.com/data-explorer/indexes/](https://docs.atlas.mongodb.com/data-explorer/indexes/)

If you’re not using Atlas, you can check this link to create the index manually: [https://docs.mongodb.com/manual/tutorial/create-indexes-to-support-queries/](https://docs.mongodb.com/manual/tutorial/create-indexes-to-support-queries/)
