The queries get stuck in aws lambda function despite successful connection

I am trying to connect to mongoDB atlas and performing some query in aws lambda. The connection is successful but the queries get stuck. Here is an example:

import User from "/opt/nodejs/model/User.js";
import Project from "/opt/nodejs/model/Project.js";

import connectDB from "/opt/database/db/connectDb.js"


export const handler = async function() {
  try {
    console.log("entered");
    const connect = await connectDB();
    console.log(connect);
    let projects = await Project.find({ sub:"sa" });
    return(projects);
  } catch (err) {
    console.error(err.message);
    return("Server error");
  }
};