Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue while connecting to database (Bug) #14960

Open
2 tasks done
faizcode24 opened this issue Oct 13, 2024 · 3 comments
Open
2 tasks done

Issue while connecting to database (Bug) #14960

faizcode24 opened this issue Oct 13, 2024 · 3 comments
Labels
can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity.
Milestone

Comments

@faizcode24
Copy link

faizcode24 commented Oct 13, 2024

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

8.7.1

Node.js version

18.13.0

MongoDB server version

i was just using Atlas

Typescript version (if applicable)

No response

Description

mongoose new version having issues while connecting the MongoDB cluster, and having the error as

Error connecting in MongoDB Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist:

despite using the 0.0.0.0 ID address its still has the issues

import mongoose from "mongoose";
const dbConnect = async () => {
    try {
     
       await mongoose.connect(process.env.MONGODB_URI)
      
        console.log("Connected to MongoDB")
    }
    catch (error){
        console.log(`Database connection failed ${error.message}`);
       
    }

Steps to Reproduce

The issue was resolved after using the older stable version 8.1.1

Expected Behavior

No response

@faizcode24 faizcode24 changed the title Isuuse while connecting to database Issue while connecting to database Oct 13, 2024
@faizcode24 faizcode24 changed the title Issue while connecting to database Issue while connecting to database (Bug) Oct 13, 2024
@vkarpov15
Copy link
Collaborator

I'm unable to repro, we have several production projects running Mongoose 8.7 connected to Atlas with no issues.

Please provide:

  1. The MongoDB server version you're running on MongoDB Atlas
  2. The error.reason property from the MongooseServerSelectionError that has the Error connecting in MongoDB Could not connect to any servers in your MongoDB Atlas cluster message you pasted. Please make sure to omit any hostnames.

@vkarpov15 vkarpov15 added the can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. label Oct 14, 2024
@calvintny
Copy link

calvintny commented Oct 15, 2024

Had the same issue doing tutorials with mongoose. Issue resolved after I rolled back to 8.6.3.

Mongoose version
8.7.1

Node.js version
18.16.0

MongoDB server version
Atlas 7.0.14

error.reason :

TopologyDescription {
  type: 'ReplicaSetNoPrimary',
  servers: Map(3) {
    'XXX:27017' => ServerDescription {
      address: 'XXX:27017',
      type: 'Unknown',
      hosts: [],
      passives: [],
      arbiters: [],
      tags: {},
      minWireVersion: 0,
      maxWireVersion: 0,
      roundTripTime: -1,
      minRoundTripTime: 0,
      lastUpdateTime: 5393564,
      lastWriteDate: 0,
      error: [MongoNetworkError],
      topologyVersion: null,
      setName: null,
      setVersion: null,
      electionId: null,
      logicalSessionTimeoutMinutes: null,
      primary: null,
      me: null,
      '$clusterTime': null
    },
    'XXX:27017' => ServerDescription {
      address: 'XXX:27017',
      type: 'Unknown',
      hosts: [],
      passives: [],
      arbiters: [],
      tags: {},
      minWireVersion: 0,
      maxWireVersion: 0,
      roundTripTime: -1,
      minRoundTripTime: 0,
      lastUpdateTime: 5387737,
      lastWriteDate: 0,
      error: [MongoNetworkError],
      topologyVersion: null,
      setName: null,
      setVersion: null,
      electionId: null,
      logicalSessionTimeoutMinutes: null,
      primary: null,
      me: null,
      '$clusterTime': null
    },
    'XXX:27017' => ServerDescription {
      address: 'XXX:27017',
      type: 'Unknown',
      hosts: [],
      passives: [],
      arbiters: [],
      tags: {},
      minWireVersion: 0,
      maxWireVersion: 0,
      roundTripTime: -1,
      minRoundTripTime: 0,
      lastUpdateTime: 5386680,
      lastWriteDate: 0,
      error: null,
      topologyVersion: null,
      setName: null,
      setVersion: null,
      electionId: null,
      logicalSessionTimeoutMinutes: null,
      primary: null,
      me: null,
      '$clusterTime': null
    }
  },
  stale: false,
  compatible: true,
  heartbeatFrequencyMS: 10000,
  localThresholdMS: 15,
  setName: 'XXX',
  maxElectionId: null,
  maxSetVersion: null,
  commonWireVersion: 0,
  logicalSessionTimeoutMinutes: null
}

@vkarpov15 vkarpov15 removed the can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. label Oct 15, 2024
@vkarpov15 vkarpov15 added this to the 8.7.2 milestone Oct 15, 2024
@vkarpov15
Copy link
Collaborator

I'm unable to repro. Running the following script against an Atlas cluster running MongoDB 7.0.14 with Mongoose 8.7.1:

const mongoose = require('mongoose');

mongoose.connect('mongodb+srv://user:[email protected]/?retryWrites=true&w=majority&appName=xyz').then(() => console.log('Connected', mongoose.connection.client.topology.s.description));

Outputs:

Connected TopologyDescription {
  type: 'ReplicaSetWithPrimary',
  servers: Map(3) {
    'abc.mongodb.net:27017' => ServerDescription {
      address: 'abc.mongodb.net:27017',
      type: 'RSSecondary',
      hosts: [Array],
      passives: [],
      arbiters: [],
      tags: [Object],
      minWireVersion: 0,
      maxWireVersion: 21,
      roundTripTime: 52,
      minRoundTripTime: 0,
      lastUpdateTime: 4511622,
      lastWriteDate: 2024-10-15T15:49:45.000Z,
      error: null,
      topologyVersion: [Object],
      setName: 'TTT',
      setVersion: 109,
      electionId: null,
      logicalSessionTimeoutMinutes: 30,
      primary: 'abc.mongodb.net:27017',
      me: 'abc.mongodb.net:27017',
      '$clusterTime': [Object]
    },
    '123.mongodb.net:27017' => ServerDescription {
      address: '123.mongodb.net:27017',
      type: 'RSPrimary',
      hosts: [Array],
      passives: [],
      arbiters: [],
      tags: [Object],
      minWireVersion: 0,
      maxWireVersion: 21,
      roundTripTime: 52,
      minRoundTripTime: 0,
      lastUpdateTime: 4511630,
      lastWriteDate: 2024-10-15T15:49:45.000Z,
      error: null,
      topologyVersion: [Object],
      setName: 'TTT',
      setVersion: 109,
      electionId: new ObjectId('7fffffff000000000000031f'),
      logicalSessionTimeoutMinutes: 30,
      primary: '123.mongodb.net:27017',
      me: '123.mongodb.net:27017',
      '$clusterTime': [Object]
    },
    'xyz.mongodb.net:27017' => ServerDescription {
      address: 'xyz.mongodb.net:27017',
      type: 'RSSecondary',
      hosts: [Array],
      passives: [],
      arbiters: [],
      tags: [Object],
      minWireVersion: 0,
      maxWireVersion: 21,
      roundTripTime: 49,
      minRoundTripTime: 0,
      lastUpdateTime: 4511636,
      lastWriteDate: 2024-10-15T15:49:45.000Z,
      error: null,
      topologyVersion: [Object],
      setName: 'TTT',
      setVersion: 109,
      electionId: null,
      logicalSessionTimeoutMinutes: 30,
      primary: 'xyz.mongodb.net:27017',
      me: 'xyz.xvnqv.mongodb.net:27017',
      '$clusterTime': [Object]
    }
  },
  stale: false,
  compatible: true,
  heartbeatFrequencyMS: 10000,
  localThresholdMS: 15,
  setName: 'TTT',
  maxElectionId: new ObjectId('7fffffff000000000000031f'),
  maxSetVersion: 109,
  commonWireVersion: 0,
  logicalSessionTimeoutMinutes: 30
}

@calvintny what OS are you using, maybe you're on Windows? I've tested on OSX and linux, both work fine.

@vkarpov15 vkarpov15 added the can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. label Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity.
Projects
None yet
Development

No branches or pull requests

3 participants