Update database.js

This commit is contained in:
Mr Swift
2024-03-17 13:16:14 +03:30
parent 95407cec57
commit c58a2dd720
+13 -9
View File
@@ -1,20 +1,24 @@
/* eslint-disable no-unused-vars */ /* eslint-disable no-unused-vars */
const mongoose = require('mongoose') 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. // 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 inHostUrl = 'mongodb://asanserv_admin:admin1234@localhost:27017/asanserv_database'
const outHostUrl = const outHostUrl =
'mongodb://asanserv_admin:admin1234@www.asan-service.com:27017/asanserv_database?serverSelectionTimeoutMS=5000&connectTimeoutMS=10000&authSource=asanserv_database' 'mongodb://asanserv_admin:admin1234@www.asan-service.com:27017/asanserv_database?serverSelectionTimeoutMS=5000&connectTimeoutMS=10000&authSource=asanserv_database'
const locaUrl = 'mongodb://localhost:27017/AsanService' const locaUrl = 'mongodb://localhost:27017/AsanService'
mongoose.connect(outHostUrl, { const init = ()=>{
useNewUrlParser: true, try {
useUnifiedTopology: true, mongoose.connect(outHostUrl, {
useFindAndModify: false, useNewUrlParser: true,
useCreateIndex: true useUnifiedTopology: true,
}) useFindAndModify: false,
useCreateIndex: true
})
} catch (error) {
init()
}
}
init()
mongoose.plugin(schema => { mongoose.plugin(schema => {
schema.set('toObject', { getters: true }) schema.set('toObject', { getters: true })
schema.set('toJSON', { getters: true }) schema.set('toJSON', { getters: true })