Files
multy-stub/server/routers/procurement/config/db.js
2025-10-23 09:49:04 +03:00

30 lines
937 B
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}`);
await mongoose.connect(mongoUri, {
serverSelectionTimeoutMS: 5000,
connectTimeoutMS: 5000,
});
console.log('✅ MongoDB подключена успешно!');
console.log(` Хост: ${mongoose.connection.host}`);
console.log(` БД: ${mongoose.connection.name}\n`);
return true;
} catch (error) {
console.error('\n❌ Ошибка подключения к MongoDB:');
console.error(` ${error.message}\n`);
console.warn('⚠️ Приложение продолжит работу с mock данными\n');
return false;
}
};
module.exports = connectDB;