Automattic / mongoose

MongoDB object modeling designed to work in an asynchronous environment.
https://mongoosejs.com
MIT License
26.92k stars 3.84k forks source link

Connect to mongodb / documentDB #14535

Closed rakshitweb closed 5 months ago

rakshitweb commented 6 months ago

Prerequisites

Mongoose version

^8.0.2

Node.js version

20.9.0

MongoDB version

5.0.0

Operating system

Windows

Operating system version (i.e. 20.04, 11.3, 10)

10

Issue

I am not able to connect to document DB using mongoose. I am able to connect to the same using mongo shell, and compass.

Getting this error: Failed to connect with Mongo DB MongooseServerSelectionError: connect ETIMEDOUT

humblewolfstudio commented 6 months ago

Can you post the code you're trying to run to connect to the document DB?

rakshitweb commented 6 months ago

` const mongoose = require('mongoose'); const dotenv = require('dotenv'); dotenv.config();

const DBConnect = () => mongoose.connect(process.env.DB_URL, { tls: true, tlsCAFile: 'global-bundle.pem', directConnection: true });

module.exports = DBConnect; `

DB_URL: mongodb://USERNAME>:<PASSWORD>@<CLUSTER_NAME:/

vkarpov15 commented 5 months ago

And how are you importing and running DBConnect() ?

FaizBShah commented 5 months ago

@rakshitweb Is this a protected DB? Because in that case you will also need to add password to the url connection string, otherwise you won't be to connect to it

humblewolfstudio commented 5 months ago

@rakshitweb https://www.mongodb.com/docs/manual/reference/connection-string/ here you have some more information about mongodb connection strings if you need it