Quando tento conectar o banco de dados, ele estoura um erro muito grande, tentei que tentei, mas não consegui resolver Código da conexão:
import mongoose from "mongoose";
mongoose.connect("mongodb+srv://joao:3344@123ss@cluster0.dhpd3.mongodb.net/MongoDb");
let db = mongoose.connection;
export default db;
//no app.js
import db from "./config/dbconnect.js";
db.on("error", console.log.bind(console,"Erro de conexão"))
db.once("open", () => {
console.log("Conexão com o banco feita com sucesso")
})
então, eu tomo o seguinte erro: Erro de conexão MongoAPIError: URI must include hostname, domain name, and tld at resolveSRVRecord (C:\vStudioCode\Arquivos JavaScript, NodeJS\NodeJS-Curso2\node_modules\mongodb\lib\connection_string.js:51:25) at connect (C:\vStudioCode\Arquivos JavaScript, NodeJS\NodeJS-Curso2\node_modules\mongodb\lib\operations\connect.js:32:57) at C:\vStudioCode\Arquivos JavaScript, NodeJS\NodeJS-Curso2\node_modules\mongodb\lib\mongo_client.js:127:35 at maybePromise (C:\vStudioCode\Arquivos JavaScript, NodeJS\NodeJS-Curso2\node_modules\mongodb\lib\utils.js:496:5) at MongoClient.connect (C:\vStudioCode\Arquivos JavaScript, NodeJS\NodeJS-Curso2\node_modules\mongodb\lib\mongo_client.js:126:41) at C:\vStudioCode\Arquivos JavaScript, NodeJS\NodeJS-Curso2\node_modules\mongoose\lib\connection.js:796:12 at new Promise () at NativeConnection.Connection.openUri (C:\vStudioCode\Arquivos JavaScript, NodeJS\NodeJS-Curso2\node_modules\mongoose\lib\connection.js:781:19) at C:\vStudioCode\Arquivos JavaScript, NodeJS\NodeJS-Curso2\node_modules\mongoose\lib\index.js:342:10 at C:\vStudioCode\Arquivos JavaScript, NodeJS\NodeJS-Curso2\node_modules\mongoose\lib\helpers\promiseOrCallback.js:32:5 node:internal/process/promises:279 triggerUncaughtException(err, true /* fromPromise */); ^
MongoAPIError: URI must include hostname, domain name, and tld at resolveSRVRecord (C:\vStudioCode\Arquivos JavaScript, NodeJS\NodeJS-Curso2\node_modules\mongodb\lib\connection_string.js:51:25) at connect (C:\vStudioCode\Arquivos JavaScript, NodeJS\NodeJS-Curso2\node_modules\mongodb\lib\operations\connect.js:32:57) at C:\vStudioCode\Arquivos JavaScript, NodeJS\NodeJS-Curso2\node_modules\mongodb\lib\mongo_client.js:127:35 at maybePromise (C:\vStudioCode\Arquivos JavaScript, NodeJS\NodeJS-Curso2\node_modules\mongodb\lib\utils.js:496:5) at MongoClient.connect (C:\vStudioCode\Arquivos JavaScript, NodeJS\NodeJS-Curso2\node_modules\mongodb\lib\mongo_client.js:126:41) at C:\vStudioCode\Arquivos JavaScript, NodeJS\NodeJS-Curso2\node_modules\mongoose\lib\connection.js:796:12 at new Promise () at NativeConnection.Connection.openUri (C:\vStudioCode\Arquivos JavaScript, NodeJS\NodeJS-Curso2\node_modules\mongoose\lib\connection.js:781:19) at C:\vStudioCode\Arquivos JavaScript, NodeJS\NodeJS-Curso2\node_modules\mongoose\lib\index.js:342:10 at C:\vStudioCode\Arquivos JavaScript, NodeJS\NodeJS-Curso2\node_modules\mongoose\lib\helpers\promiseOrCallback.js:32:5