# How to use MongoDB in your serverless app

**URL:** <https://discourse.sst.dev/t/how-to-use-mongodb-in-your-serverless-app/2406>\
**Category:** Chapter Comments\
**Created:** [June 4, 2021, 7:26pm UTC](https://discourse.sst.dev/t/how-to-use-mongodb-in-your-serverless-app/2406 "2021-06-04T19:26:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [June 4, 2021, 7:26pm UTC](https://discourse.sst.dev/t/how-to-use-mongodb-in-your-serverless-app/2406/1 "2021-06-04T19:26:39Z")

</div>

Link to chapter — [https://serverless-stack.com/examples/how-to-use-mongodb-in-your-serverless-app.html](https://serverless-stack.com/examples/how-to-use-mongodb-in-your-serverless-app.html)

---

<div class="post-metadata">

**Author:** ![bike-bill](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/bike-bill/32/1220_2.png) [@bike-bill](https://discourse.sst.dev/u/bike-bill)\
**Post date:** [February 7, 2022, 3:41pm UTC](https://discourse.sst.dev/t/how-to-use-mongodb-in-your-serverless-app/2406/2 "2022-02-07T15:41:20Z")

</div>

We had a lot of connectivity issues when saving a moderate stream of data when we used the MongoClient to connect to an Atlas Mongo cluster. The issue was we’d lose the connection for a few minutes to even an hour or two even though we tried to cache and reuse it as suggested here and [by Atlas](https://docs.atlas.mongodb.com/best-practices-connecting-from-aws-lambda/).

Fortunately, we are seeing much better results after we dropped the MongoClient and replaced it with Atlas’ [Data API](https://docs.atlas.mongodb.com/api/data-api/)

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [February 7, 2022, 4:28pm UTC](https://discourse.sst.dev/t/how-to-use-mongodb-in-your-serverless-app/2406/3 "2022-02-07T16:28:43Z")

</div>

Oh that’s interesting. Let me pass that feedback along and find out what the right approach is.
