All files / src/configuration databaseConnections.js

71.42% Statements 5/7
50% Branches 2/4
100% Functions 1/1
71.42% Lines 5/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19    79x   79x         79x 79x 79x              
import { connect } from "mongoose";
 
let MONGO_DB_LINK = `mongodb://${process.env.NODE_ENV === "testing" ? "localhost:27017" : "mongodbPrimary"}/?directConnection=true`;
 
Iif (process.env.DATABASE_CONNECTION_TYPE === "remote") {
    MONGO_DB_LINK = `mongodb+srv://${process.env.DB_USERNAME}:${process.env.DB_PASSWORD}@${process.env.DB_HOST}/${process.env.DB_NAME}?retryWrites=true&w=majority`;
}
 
async function databaseConnections() {
    try {
        await connect(MONGO_DB_LINK);
        console.log("connected to Mongodb successfully");
    } catch (err) {
        console.log("failed database connection", err.message);
    }
}
 
export default databaseConnections