This commit is contained in:
Swift
2024-02-13 20:54:56 +03:30
parent f0040c1748
commit 7a38f7a9e6
5 changed files with 41 additions and 59 deletions
+9 -8
View File
@@ -1,14 +1,7 @@
/* eslint-disable no-unused-vars */
const mongoose = require('mongoose')
mongoose.plugin(schema => {
schema.set('toObject', { getters: true })
schema.set('toJSON', { getters: true })
schema.set('timestamps', {
createdAt: 'created_at',
updatedAt: 'updated_at'
})
})
// 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'
@@ -22,6 +15,14 @@ mongoose.connect(outHostUrl, {
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() {