Files
multy-stub/server/routers/procurement/config/db.js
2025-10-27 18:58:38 +03:00

32 lines
1.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const mongoose = require('mongoose');
const connectDB = async () => {
try {
const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/procurement_db';
console.log('\n📡 Попытка подключения к MongoDB...');
console.log(` URI: ${mongoUri}`);
const connection = await mongoose.connect(mongoUri, {
useNewUrlParser: true,
useUnifiedTopology: true,
serverSelectionTimeoutMS: 5000,
connectTimeoutMS: 5000,
});
console.log('✅ MongoDB подключена успешно!');
console.log(` Хост: ${connection.connection.host}`);
console.log(` БД: ${connection.connection.name}\n`);
return connection;
} catch (error) {
console.error('\n❌ Ошибка подключения к MongoDB:');
console.error(` ${error.message}\n`);
console.warn('⚠️ Приложение продолжит работу с mock данными\n');
return null;
}
};
module.exports = connectDB;