Netlify lambda & MongoDB time out


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 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!

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.

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 , 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:

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

As I mentioned in the post 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:

If you’re not using Atlas, you can check this link to create the index manually:

1 Like