Cannot connect Mongodb Atlas data, with qwik framework and express server

Hi, really I need your help with this.
I am building a web app with Qwik framework, Express, Mongodb, and Netlify (also implementing netlify functions). See my site here: https://nexasoft.netlify.app/. Then I am trying to read data from Mongo Atlas so I created a function to connect this DataBase.

import { MongoClient, ServerApiVersion } from "mongodb";
// Variables de entorno
const DB_USER = import.meta.env.VITE_DB_USER;

const MONGO_HOST = `mongodb+srv://${DB_USER}:${DB_PASSWORD}@${DB_HOST}?retryWrites=true&w=majority`;

export const mongoClient = new MongoClient(MONGO_HOST, {
  useNewUrlParser: true,
  useUnifiedTopology: true,
  serverApi: ServerApiVersion.v1,
});

const clientPromise = mongoClient.connect();

const connectDB = async () => {
  try {
    const database = (await clientPromise).db(DB_NAME);
    console.log("[db] Conectada con éxito", database);
    const collection = database.collection(MONGODB_COLLECTION);
    const results = await collection.find({}).toArray();
    return {
      statusCode: 200,
      body: JSON.stringify(results),
    };
  } catch (err) {
    console.error("[db] Error", MONGO_HOST, err);
    return { statusCode: 500, body: err.toString() };
  }
};

export default connectDB;

Then from express I use a route to implement this function and get data for my component with a fetch request. But I have not achieve to read my database info.

app.get("/api/allnames", async (req, res) => {
  const docs = await connectDB();
  console.log("Call docs", docs);
  res.json(docs);
});

When I run pnpm start with my local config fetch("http://localhost:5173/api/allnames/"), I get that it returns as response a 404 code with no documents. Then If I run pnpm build with my production config fetch("https://nexasoft.netlify.app/api/allnames/"), my app build correctly in my computer, then I push it to github where the Netlify deploy fails with this:

[ERROR] Could not resolve "/opt/build/repo/adaptors/express/vite.config.ts"

I also run the command, netlify dev, witch opens the content from my site but still I get the 404 message trying to access my data from Mongo.

So I decided to install, Netlyfy functions to serverless. I created a new function get_contacts witch made my MongoDB conection and call (there I import my .env variables like, process.env…). Again running with this configuration, netlify dev or even pnpm start, the explorer shows me, Could not proxy request. Then the terminal closed with this:

TypeError: Failed to parse URL from /.netlify/functions/get_contacts. 
TypeError [ERR_INVALID_URL]: Invalid URL

I have not any idea witch could be my mistake, here my github repository: GitHub - Maikpwwq/nexasoft: Sitio Web de NexaSoft, el futuro en soluciones de software.

My fetch called was falling because I don’t used full URL: (host + function), ie. fetch("https://nexasoft.netlify.app/.netlify/functions/get_contacts. I made this change, then my consult with Mongo was taking a little over 10 seconds to respond to database query. And Netlify serverless function has this restriction in time. Then I tried to optimize my Mongo queries installing mongoose, I update my serverless function, but in the explorer I get this just a empty array (res). Maybe someone have idea of how to debug this.

This is my function get_mongoose:

import mongoose from "mongoose"; // ,
import * as dotenv from "dotenv";
dotenv.config();

// Variables de entorno
const DB_USER = `${process.env.VITE_DB_USER}`;
const DB_PASSWORD = `${process.env.VITE_DB_PASSWORD}`;
const DB_HOST = `${process.env.VITE_DB_HOST}`;
const DB_NAME = `${process.env.VITE_DB_NAME}`;
const MONGODB_COLLECTION = `${process.env.VITE_MONGODB_COLLECTION}`;

const MONGO_HOST = `mongodb+srv://${DB_USER}:${DB_PASSWORD}@${DB_HOST}/?retryWrites=true&w=majority`;

const schema = new mongoose.Schema({ name: "string", email: "string" });

console.log("MONGOOSE_HOST", MONGO_HOST);
const clientPromise = mongoose.createConnection(MONGO_HOST, {
  dbName: DB_NAME,
  useNewUrlParser: true,
  useUnifiedTopology: true,
});

const Contactos = clientPromise.model(MONGODB_COLLECTION, schema);

const handler = async () => {
  console.log("hi mongoose");
  try {
    await Contactos.find().exec().then((res) => {
      console.log("res", res);
    }); // .toArray(); .exec() .clone()
    // You don't need callbacks in Mongoose, because Mongoose supports promises and async/await.
    // , function (err, docs) { if (err) console.log("Error getting the data", err);
    // docs.forEach
    const results = [];
    console.log("mongoClient", results);
    return {
      statusCode: 200,
      body: JSON.stringify(results),
    };
  } catch (err) {
    console.error("[db] Error", MONGO_HOST, err);
    return { statusCode: 500, body: err.toString() };
  }
};

export { clientPromise, handler };

Hi,
I’m working with Qwik and Mongodb as well and everything is working as expected locally with npm run dev but when I run npm run build.server or pnpm run build I get this error: [commonjs] Cannot bundle Node.js built-in "stream" imported from "node_modules/mongodb/lib/cursor/abstract_cursor.js". Consider disabling ssr.noExternal or remove the built-in dependency. I tried adding

`
ssr: { 
      noExternal: ['mongodb'],
    }

to vite.config.ts but it didn’t solve it.
Did you have this issue?