{"size": 1267, "ext": "js", "max_stars_repo_path": "models/database.js", "max_stars_repo_name": "chuangyu-hscy/ubiquitous-carnival", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "models/database.js", "max_issues_repo_name": "chuangyu-hscy/ubiquitous-carnival", "max_issues_repo_issues_event_min_datetime": "2021-10-10T07:05:27.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-10T06:55:58.000Z", "max_forks_repo_path": "models/database.js", "max_forks_repo_name": "chuangyu-hscy/ubiquitous-carnival", "max_forks_repo_forks_event_min_datetime": "2021-11-21T10:51:37.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-21T10:51:37.000Z"}
{"max_stars_count": null, "max_issues_count": 56, "max_forks_count": 1, "avg_line_length": 25.34, "max_line_length": 101, "alphanum_fraction": 0.7063930545}
const dotenv = require("dotenv");
dotenv.config();

const mongoose = require("mongoose");

// if the app is running on heroku
if (process.env.PORT) {
  // login details retrieved from environment variables
  connectionString =
    "mongodb+srv://<username>:<password>@cluster0.upm63.mongodb.net/CRM?retryWrites=true&w=majority";

  dbAddress = connectionString
    .replace("<username>", process.env.MONGO_USERNAME)
    .replace("<password>", process.env.MONGO_PASSWORD);
} else {
  // we are running locally
  dbAddress =
    "mongodb+srv://4399:tBbXaMrp6MmEs5Iu@cluster0.upm63.mongodb.net/CRM?retryWrites=true&w=majority";
}

// connect to mongodb database
mongoose.connect(dbAddress, {
  useNewUrlParser: true,
  useCreateIndex: true,
  useUnifiedTopology: true,
  useFindAndModify: false,
  dbName: "CRM",
});

// connect to the database
const db = mongoose.connection;

db.on("error", (err) => {
  console.error(err);
  process.exit(1);
});

db.once("open", async () => {
  console.log("Mongo connection started on " + db.host + ":" + db.port);
});

// obtain the database schemas

require("./connection_test_schema");
require("./contactSchema");
require("./recordSchema");
require("./userSchema");
require("./emailAuthSchema");
require("./fastRegisterSchema");
