Using getServerSideProps
within my NextJS + MongoDB app makes it timeout when deployed.
Loading times and server responses are incredibly slow as well.
I'm using them like this:
const clientPromise = await getClient()
const posts = await clientPromise
.db(process.env.NEXT_PUBLIC_DATABASE_LABEL)
.collection("articles")
.find({"type": "nouvelle"},
{projection: { "_id": 0, "title": 1, "titleSlug": 1, "type": 1, "imageUrl": 1, "author": 1 }})
.sort({ $natural: -1 })
.limit(2)
.toArray()
await clientPromise.close()
return { props: {...{posts}} }
Dependencies:
"mongodb": "^4.8.0",
"next": "^13.2.1",
Is something wrong, or is there any way to optimize it?