Files
freeplanet_serverside/src/server/db/mongoose.js

56 lines
1.7 KiB
JavaScript
Raw Normal View History

var mongoose = require('mongoose').set('debug', process.env.DEBUG)
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-06 18:48:32 +01:00
mongoose.plugin(schema => {
schema.options.usePushEach = true
});
mongoose.set('debug', process.env.DEBUG);
2019-02-06 18:48:32 +01:00
const options = {
2019-02-08 17:11:33 +01:00
// user: process.env.UDB,
// pass: process.env.PDB,
// useMongoClient: true,
2021-06-04 10:07:57 +02:00
// useMongoClient: false,
useNewUrlParser: true,
// useFindAndModify: false,
// useCreateIndex: true,
useUnifiedTopology: true,
promiseLibrary: require('bluebird'),
// 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
};
const db = mongoose.connection;
2019-02-08 17:11:33 +01:00
// mongoose.connect(process.env.MONGODB_URI + '?authSource=admin', { options })
// console.log(' -> PASSAGGIO PARAMETRI MONGOOSE')
mongoose.connect(process.env.MONGODB_URI, options);
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)
});
2018-12-24 20:31:02 +01:00
module.exports = {mongoose};