Mail.ruПочтаМой МирОдноклассникиВКонтактеИгрыЗнакомстваНовостиКалендарьОблакоЗаметкиВсе проекты

MongoDB в чем ошибка?

Челик) Ученик (1), открыт 1 неделю назад
// migrate-mongo-config.js
require('dotenv').config();
// In this file you can configure migrate-mongo

const config = {
mongodb: {
// TODO Change (or review) the url to your MongoDB:
url: process.env.NEXT _PUBLIC_DB_URL,

// TODO Change this to your database name:
databaseName: process.env.NEXT _PUBLIC_DB_NAME,

options: {
// ssl: true,
// sslValidate: true,
// useNewUrlParser: false, // removes a deprecation warning when connecting
// useUnifiedTopology: false, // removes a deprecating warning when connecting
// connectTimeoutMS: 3600000, // increase connection timeout to 1 hour
// socketTimeoutMS: 3600000, // increase socket timeout to 1 hour
}
},

// The migrations dir, can be an relative or absolute path. Only edit this when really necessary.
migrationsDir: "migrations",

// The mongodb collection where the applied changes are stored. Only edit this when really necessary.
changelogCollectionName: "changelog",

// The file extension to create migrations and search for in migration dir
migrationFileExtension: ".js",

// Enable the algorithm to create a checksum of the file contents and use that in the comparison to determine
// if the file should be run. Requires that scripts are coded to be run multiple times.
useFileHash: false,

// Don't change this, unless you know what you're doing
moduleSystem: 'commonjs',
};

module.exports = config;


// папка migrations > 20240612103445-cloth.js
const { Faker } = require('@fakerjs/faker');

module.exports = {
async up(db, client) {
return db.collection('cloth').insertMany([{ test: 'test' }]);
},
async down(db) {
return db.collection('cloth').deleteMany({});
},
};


Ошибка -
$ migrate-mongo up
ERROR: 44330000:error:0A000438:SSL routines:ssl3_read_bytes:tlsv1 alert internal error:c:\ws\deps\openssl\openssl\ssl\record\rec_layer_s3.c:1590:SSL alert number 80
MongoServerSelectionError: 44330000:error:0A000438:SSL routines:ssl3_read_bytes:tlsv1 alert internal error:c:\ws\deps\openssl\openssl\ssl\record\rec_layer_s3.c:1590:SSL alert number 80

at Topology.selectServer (C:\Users\Admin\AppData\Roaming\npm\node_modules\migrate-mongo\node_modules\mongodb\lib\sdam\topology.js:303:38)
at async Topology._connect (C:\Users\Admin\AppData\Roaming\npm\node_modules\migrate-mongo\node_modules\mongodb\lib\sdam\topology.js:196:28)
at async Topology.connect (C:\Users\Admin\AppData\Roaming\npm\node_modules\migrate-mongo\node_modules\mongodb\lib\sdam\topology.js:158:13)
at async topologyConnect (C:\Users\Admin\AppData\Roaming\npm\node_modules\migrate-mongo\node_modules\mongodb\lib\mongo_client.js:204:17)
at async MongoClient._connect (C:\Users\Admin\AppData\Roaming\npm\node_modules\migrate-mongo\node_modules\mongodb\lib\mongo_client.js:217:13)
at async MongoClient.connect (C:\Users\Admin\AppData\Roaming\npm\node_modules\migrate-mongo\node_modules\mongodb\lib\mongo_client.js:142:13)
at async MongoClient.connect (C:\Users\Admin\AppData\Roaming\npm\node_modules\migrate-mongo\node_modules\mongodb\lib\mongo_client.js:295:16)
at async Object.connect (C:\Users\Admin\AppData\Roaming\npm\node_modules\migrate-mongo\lib\env\database.js:16:20)
1 ответ
Улик Додиков Искусственный Интеллект (108635) 1 неделю назад
GPT-4o
Ваша проблема связана с конфигурацией подключения к MongoDB через SSL. Ошибка указывает на проблемы с SSL-соединением. Чтобы устранить проблему, попробуйте следующее:

1. **Исправьте опечатки в переменных окружения**:
Убедитесь, что переменные окружения правильно написаны и не содержат лишних пробелов.
    url: process.env.NEXT_PUBLIC_DB_URL,  
databaseName: process.env.NEXT_PUBLIC_DB_NAME,


2. **Настройка SSL в конфигурации**:
Попробуйте включить опции `useNewUrlParser` и `useUnifiedTopology` и убедитесь, что они установлены в `true`. Также попробуйте настроить SSL, если ваш MongoDB требует SSL-соединения.
 options: {  
ssl: true,
sslValidate: true,
useNewUrlParser: true,
useUnifiedTopology: true,
connectTimeoutMS: 3600000,
socketTimeoutMS: 3600000,
}


3. **Проверка переменных окружения**:
Убедитесь, что переменные окружения `NEXT_PUBLIC_DB_URL` и `NEXT_PUBLIC_DB_NAME` правильно заданы в вашем `.env` файле.

4. **Проверка версии Node.js**:
Убедитесь, что используемая версия Node.js поддерживает все необходимые функции и библиотеки.

Если вы все еще сталкиваетесь с проблемами, попробуйте отключить SSL, чтобы проверить, связана ли проблема с этим:

 options: {  
ssl: false,
useNewUrlParser: true,
useUnifiedTopology: true,
connectTimeoutMS: 3600000,
socketTimeoutMS: 3600000,
}


Если отключение SSL решает проблему, возможно, у вас проблемы с сертификатом или настройками SSL. В этом случае, вам нужно будет убедиться, что у вас есть правильные сертификаты и настройки для подключения к вашей базе данных MongoDB.
Похожие вопросы