/* eslint-disable no-unused-vars */
const mongoose = require('mongoose')



// mongodb database connection string. change it as per your needs. here "mydb" is the name of the database. You don't need to create DB from mongodb terminal. mongoose create the database automatically.
const inHostUrl = 'mongodb://asanserv_admin:admin1234@localhost:27017/asanserv_database'
const outHostUrl =
  'mongodb://asanserv_admin:admin1234@www.asan-service.com:27017/asanserv_database?serverSelectionTimeoutMS=5000&connectTimeoutMS=10000&authSource=asanserv_database'
const locaUrl = 'mongodb://localhost:27017/AsanService'
mongoose.connect(outHostUrl, {
  useNewUrlParser: true,
  useUnifiedTopology: true,
  useFindAndModify: false,
  useCreateIndex: true
})

mongoose.plugin(schema => {
  schema.set('toObject', { getters: true })
  schema.set('toJSON', { getters: true })
  schema.set('timestamps', {
    createdAt: 'created_at',
    updatedAt: 'updated_at'
  })
})
const database = mongoose.connection
database.on('error', console.error.bind(console, 'connection error:'))
database.once('open', function callback() {
  console.log('🟠 ~ MongoDB Connected...')
})

module.exports = database
