'TypeError: Cannot Read properties of undefined (reading 'close')

i'm trying to close connection with database after getting data in an asynchronous function but i get Error from mongoose.disconnect function , i tried to read the docs and some articls about mongoose but i didn't find any solution to my issue

const mongoose = require('mongoose');
const dbURL= 'mongodb://localhost:27017/chat-app';
const User = mongoose.model("user",userShema);

const getFriendRequests = async () =>{
    try {
        await mongoose.connect(dbURL);
        let data = await User.find();
        mongoose.disconnect();
        return data
    } catch(err) {
        mongoose.disconnect();
        throw new Error(err)
    }
}

the Error shown in terminal

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source