Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | 4x 8x 4x 4x 4x 4x 4x 4x 4x 4x 4x 57x 57x 342x 4x | const mongoose = require('mongoose');
let connection;
async function connect() {
if (connection) return;
const uri =
process.env.MONGODB_SLACK_URL
connection = mongoose.connection;
connection.once('open', () =>
console.log('Connection established successfully')
);
connection.on('disconnected', () => console.log('Succesfully disconnected'));
connection.on('error', (err) => console.log('Something went wrong', err));
await mongoose.connect(uri);
}
async function disconnected() {
Iif (!connection) return;
await mongoose.disconnect();
}
async function cleanup() {
Iif (!connection) return;
for (const collection in connection.collections) {
await connection.collections[collection].deleteMany({});
}
}
module.exports = { connect, disconnected, cleanup };
|