import { databaseConfig } from "$config/index.js";
import { appConfig } from "$config/index.js";

import mongoose from "mongoose";

const { mongoConfig } = databaseConfig;

let url = `mongodb://${mongoConfig.host}/${mongoConfig.name}`;

if (appConfig.environment === "production") {
  url = `mongodb://${mongoConfig.user}:${mongoConfig.pass}@${mongoConfig.host}/${mongoConfig.name}`;
}

const connection = mongoose.createConnection(url);

export default connection;
