74 lines
2.2 KiB
JavaScript
Executable File
74 lines
2.2 KiB
JavaScript
Executable File
var mongoose = require('mongoose').set('debug', false)
|
|
|
|
mongoose.Promise = global.Promise;
|
|
|
|
mongoose.level = "";
|
|
|
|
|
|
mongoose.plugin(schema => {
|
|
schema.options.usePushEach = true
|
|
});
|
|
|
|
mongoose.set('debug', false);
|
|
|
|
let options = {
|
|
// user: process.env.UDB,
|
|
// pass: process.env.PDB,
|
|
// useMongoClient: true,
|
|
// useMongoClient: false,
|
|
useNewUrlParser: true,
|
|
// useFindAndModify: 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.
|
|
};
|
|
|
|
if (process.env.AUTH_MONGODB === '1') {
|
|
options.auth = {
|
|
authSource: "admin",
|
|
poolSize: 10,
|
|
user: process.env.MONGODB_USER,
|
|
password: process.env.MONGODB_PWD,
|
|
};
|
|
}
|
|
|
|
if (options.auth && options.auth.user) {
|
|
console.log('MongoDb con Authenticazione:', options.auth.user, '******');
|
|
} else {
|
|
console.log('### MongoDb SENZA Authenticazione !!! ');
|
|
}
|
|
|
|
const db = mongoose.connection;
|
|
|
|
console.log('Node Version ' + process.version);
|
|
console.log('Mongoose Version ' + mongoose.version);
|
|
|
|
connectionUrl = process.env.MONGODB_URI;
|
|
|
|
console.log('Connessione a ' + connectionUrl + ' in corso...');
|
|
mongoose.connect(connectionUrl, options);
|
|
|
|
db.on('error', console.error.bind(console, 'connection error:'));
|
|
db.once('open', function () {
|
|
// we're connected!
|
|
console.log('*** CONNESSIONE EFFETTUATA ! ' + connectionUrl + ' db: ' + process.env.DATABASE)
|
|
|
|
});
|
|
|
|
module.exports = { mongoose };
|