setting up dotenv and stuff
This commit is contained in:
@@ -1,18 +1,19 @@
|
||||
// External Dependencies
|
||||
import * as mongoDB from "mongodb";
|
||||
// import * as dotenv from "dotenv";
|
||||
|
||||
import { loadConfig } from "../config";
|
||||
|
||||
// Global Variables
|
||||
|
||||
export const collections: {
|
||||
users?: mongoDB.Collection;
|
||||
relationships?: mongoDB.Collection;
|
||||
} = {};
|
||||
|
||||
// Initialize Connection
|
||||
export async function connectToDatabase() {
|
||||
const config = loadConfig();
|
||||
|
||||
const client: mongoDB.MongoClient = new mongoDB.MongoClient(
|
||||
"mongodb+srv://default:[email protected]/default?retryWrites=true&w=majority"
|
||||
config.MONGO_CONNECTION_STRING
|
||||
);
|
||||
|
||||
await client.connect();
|
||||
@@ -20,11 +21,8 @@ export async function connectToDatabase() {
|
||||
const db: mongoDB.Db = client.db(process.env.DB_NAME);
|
||||
|
||||
const usersCollection: mongoDB.Collection = db.collection("users");
|
||||
const relationshipCollection: mongoDB.Collection =
|
||||
db.collection("relationships");
|
||||
|
||||
collections.users = usersCollection;
|
||||
collections.relationships = relationshipCollection;
|
||||
|
||||
console.log(
|
||||
`Successfully connected to database: ${db.databaseName} and collections`
|
||||
|
||||
Reference in New Issue
Block a user