2022-09-14 11:32:04 +02:00
|
|
|
var mongoose = require('mongoose').set('debug', false)
|
2018-12-24 20:31:02 +01:00
|
|
|
|
|
|
|
|
mongoose.Promise = global.Promise;
|
2019-02-05 03:40:22 +01:00
|
|
|
|
2019-02-06 18:48:32 +01:00
|
|
|
mongoose.level = "";
|
|
|
|
|
|
2019-02-13 01:51:33 +01:00
|
|
|
|
2019-02-06 18:48:32 +01:00
|
|
|
mongoose.plugin(schema => {
|
|
|
|
|
schema.options.usePushEach = true
|
|
|
|
|
});
|
|
|
|
|
|
2022-09-14 11:32:04 +02:00
|
|
|
mongoose.set('debug', false);
|
2019-02-06 18:48:32 +01:00
|
|
|
|
2020-01-13 23:52:51 +01:00
|
|
|
const options = {
|
2019-02-08 17:11:33 +01:00
|
|
|
// user: process.env.UDB,
|
|
|
|
|
// pass: process.env.PDB,
|
2020-01-13 23:52:51 +01:00
|
|
|
// useMongoClient: true,
|
2021-06-04 10:07:57 +02:00
|
|
|
// useMongoClient: false,
|
2020-01-13 23:52:51 +01:00
|
|
|
useNewUrlParser: true,
|
2022-09-14 11:32:04 +02:00
|
|
|
// useFindAndModify: true,
|
|
|
|
|
useFindAndModify: false,
|
2022-09-11 11:45:33 +02:00
|
|
|
// useCreateIndex: true,
|
2020-01-13 23:52:51 +01:00
|
|
|
useUnifiedTopology: true,
|
|
|
|
|
|
|
|
|
|
promiseLibrary: require('bluebird'),
|
2019-02-12 19:10:58 +01:00
|
|
|
|
|
|
|
|
// autoIndex: false, // Don't build indexes
|
|
|
|
|
// reconnectTries: Number.MAX_VALUE, // Never stop trying to reconnect
|
|
|
|
|
// reconnectInterval: 500, // Reconnect every 500ms
|
|
|
|
|
// poolSize: 10, // Maintain up to 10 socket connections
|
|
|
|
|
// // If not connected, return errors immediately rather than waiting for reconnect
|
|
|
|
|
// bufferMaxEntries: 0,
|
|
|
|
|
// connectTimeoutMS: 10000, // Give up initial connection after 10 seconds
|
|
|
|
|
// socketTimeoutMS: 45000, // Close sockets after 45 seconds of inactivity
|
|
|
|
|
// family: 4 // Use IPv4, skip trying IPv6
|
|
|
|
|
|
|
|
|
|
// keepAlive: true, // keepAlive is true by default since mongoose 5.2.0
|
|
|
|
|
// keepAliveInitialDelay: 300000 // keepAliveInitialDelay is the number of milliseconds to wait before initiating keepAlive on the socket.
|
2019-02-08 17:11:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2020-01-13 23:52:51 +01:00
|
|
|
const db = mongoose.connection;
|
|
|
|
|
|
2019-02-08 17:11:33 +01:00
|
|
|
|
|
|
|
|
// mongoose.connect(process.env.MONGODB_URI + '?authSource=admin', { options })
|
2021-09-22 01:13:41 +02:00
|
|
|
// console.log(' -> PASSAGGIO PARAMETRI MONGOOSE')
|
2023-09-27 18:38:57 +02:00
|
|
|
console.log('Node Version ' + process.version);
|
|
|
|
|
console.log('Mongoose Version ' + mongoose.version);
|
|
|
|
|
console.log('Connessione a ' + process.env.MONGODB_URI + ' in corso...');
|
2020-01-13 23:52:51 +01:00
|
|
|
mongoose.connect(process.env.MONGODB_URI, options);
|
2019-10-05 20:01:56 +02:00
|
|
|
|
2020-01-13 23:52:51 +01:00
|
|
|
db.on('error', console.error.bind(console, 'connection error:'));
|
|
|
|
|
db.once('open', function() {
|
|
|
|
|
// we're connected!
|
2021-06-04 10:07:57 +02:00
|
|
|
console.log('*** CONNESSIONE EFFETTUATA ! ' + process.env.MONGODB_URI + ' db: ' + process.env.DATABASE)
|
2020-01-13 23:52:51 +01:00
|
|
|
|
|
|
|
|
});
|
2018-12-24 20:31:02 +01:00
|
|
|
|
|
|
|
|
module.exports = {mongoose};
|