Error mongodb must be connected to perform this action

i have deployed my Next js app on versel and using mongodb altas for database, I sometimes get this error “mongodb uust be connected to perform this operation”. This error never occurs on locahost it occurs on versel and it occurs sometimes not everytime.

Here is my code

import nc from 'next-connect';
import db from '../../../utils/db';
import User from '../../../models/User';
import bcrypt from 'bcryptjs/dist/bcrypt';
import { signToken } from '../../../utils/auth';

const handler = nc();

handler.post(async (req, res) => {
    await db.connect();
    var isSupplier=false;
    var zipcode=false;
    if(req.body.isSupplier!=undefined)
    {
          isSupplier= true;
    }
    else{
        isSupplier=false;
    }
    if(req.body.zipcode!=undefined)
    {
       
        zipcode=req.body.zipcode;
    }
    else{
        zipcode="";
    }
    const newUser = new User(
        {
            firstName: req.body.firstName,
            lastName: req.body.lastName,
            email: req.body.email,
            password: bcrypt.hashSync(req.body.password),
            isAdmin: false,
            isSupplier:isSupplier,
            zipcode:zipcode
            
        }
    );
 
     try {
        const user = await newUser.save();
    
        const token = signToken(user);
        res.send(
        {
            token,
            _id: user._id,
            firstName: user.firstName,
            lastName: user.lastName,
            email: user.email,
            isAdmin: user.isAdmin,
            isSupplier: user.isSupplier,
            zipcode: user.zipcode
        }
        );
     }
     catch(err) {
        const {code} = err
        var message;
        console.log(err);
        if (code === 11000) {
           message="Email already exists"
        }
        else
        {
            message="An error occured"
        }
        res.status(500).json({
          message: message,
          error: err
        });
      }
    await db.disconnect();
    
        
    
    
    
});

export default handler;

Excuse me. Could you find the error? I have exactly the same problem. Thank you