#MongoDB Atlas and Vercel - still hitting connection limits

4 messages · Page 1 of 1 (latest)

umbral elm
#

Hi guys,
I wanted to know, if anybody ever found a way to fix Payload spamming the complete MongoDB with 400+ connections on basic usage? I created a global connection singleton:

import configPromise from '@payload-config'
import { getPayload } from 'payload'
import type { Payload } from 'payload'

let payloadClientPromise: Promise<Payload> | null = null

/**
 * Get the global payload client instance. Payload should ALWAYS be initialized this way to ensure
 * that the client is only created once and is reused across the application.
 * @returns The payload client instance.
 */
export async function getPayloadClient(): Promise<Payload> {
  if (!payloadClientPromise) {
    payloadClientPromise = getPayload({ config: configPromise }).catch((error) => {
      payloadClientPromise = null
      throw error
    })
  }

  return payloadClientPromise
}

but that didnt change a thing... what did you do to solve this issue?

umbral elm
simple tendon
#

Can you share more about your project? Did you build this off one of our templates?