Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const mongodb = require('mongodb');
- const MongoClient = mongodb.MongoClient;
- const config = require('../config');
- const url = config.connectionString;
- let connection;
- const getConnection = () => connection;
- let users;
- let log;
- module.exports = {
- getConnection: getConnection,
- closeConnection: () => {
- if (connection) {
- connection.close();
- }
- },
- init: () => {
- process.once('SIGUSR2', () => {
- connection.close(() => {
- process.kill(process.pid, 'SIGUSR2');
- });
- });
- return MongoClient
- .connect(url)
- .then((conn) => {
- console.log('Connected to MongoDB');
- connection = conn;
- users = conn.collection('users');
- log = conn.collection('log');
- return connection;
- });
- },
- collections: {
- users: () => users,
- log: () => log,
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement