Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
926 B
20
Indexable
Never

const mongoose = require("mongoose")


const connect = async (uri) => {
    try {
        await mongoose.createConnection(uri, { useNewUrlParser: true, useUnifiedTopology: true }, () => console.log("[DB] Connected to database."));
    } catch (error) {
        console.error(error);
    }

    const connection = mongoose.connection;
    connection.on("connecting", () => console.log("[DB] Connecting to database..."));
    connection.on("error", (err) => console.log("[DB] Error connecting to database" + "\n" + err))
    connection.on("open", () => console.log("[DB] Database is ready."));
    connection.on("disconnected", () => console.log("[DB] Disconnected from the database... reconnecting..."));
    connection.on("reconnected", () => console.log("[DB] Reconnected to the database."));
}

module.exports = connect;




i dont get any errors and for some reason `mongoose.connection.readyState` is always `0`
any idea?