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 | import mongoose from 'mongoose'; import { ConnectionOptions } from 'tls'; // Função para conectar ao MongoDB export async function connectToMongoDB(): Promise<void> { try { // URL de conexão com o MongoDB //const mongoURL = 'mongodb://root:example@localhost:27017/databaserbr'; const mongoURL = 'mongodb://root:example@mongo:27017/databaserbr'; // Conexão com o MongoDB await mongoose.connect(mongoURL, { useUnifiedTopology: true, authSource: 'admin' // O banco de dados de autenticação } as ConnectionOptions); console.log('Conexão bem-sucedida com o MongoDB.'); } catch (error) { console.error('Erro ao conectar ao MongoDB:', error); throw error; } } export const disconnectFromMongoDB = async () => { await mongoose.disconnect(); }; |