Skip to content
This repository has been archived by the owner on May 31, 2022. It is now read-only.

Connect Error #186

Open
dahudson88 opened this issue Jul 11, 2018 · 2 comments
Open

Connect Error #186

dahudson88 opened this issue Jul 11, 2018 · 2 comments

Comments

@dahudson88
Copy link

We are attempting to access a mongo DB via a shell as shown in your example. We are getting an error when trying to connect with the following options:

const connect = require('mongodb-connection-model').connect;
const options = {
  hostname: 'localhost',
  port: 27017,
  ssh_tunnel: 'IDENTITY_FILE',
  ssh_tunnel_hostname: 'ec2-##-###-###-###.compute-1.amazonaws.com',
  ssh_tunnel_username: 'ubuntu',
  ssh_tunnel_identity_file: ['FILE.pem'],
  mongodb_username: 'mongoUser',
  mongodb_password: '######',
  mongodb_database_name:'mongoDataBase'
};

Below is how we are calling the function

 connect(options, (e, db) => {
      if (e) {
        return console.log('E', e);
      }
      db.db('mongoDataBase').collection('myCollect').count((err2, count) => {
        console.log('counted:', err2, count);
        db.close();
      });
    }).on('status', (evt) => console.log('status:', evt));

The error message that we are getting is:

 MongoClient {
  domain: null,
  _events: {},
  _eventsCount: 0,
  _maxListeners: undefined,
  s: 
   { url: 'mongodb://mongoUser:[email protected]:29464/?readPreference=primary&authSource='mongoDataBase',
     options: { useNewUrlParser: true },
     promiseLibrary: [Function: Promise],
     dbCache: {},

When we look at the status values we get:

status: { message: 'Create SSH Tunnel', complete: true }
status: { message: 'Connect to MongoDB', pending: true }
status: { message: 'Connect to MongoDB', complete: true }

One of the concerns that I see is that thought the port in options is defined as 27017 each time I attempt to call the connect function a different port is used. (ie: 29464 as shown above). I believe that this may be the root to the problem but unsure how to resolve. Additionally we never get to the db calls that are being used. Any ideas what could be going wrong here?

@pvcon13
Copy link

pvcon13 commented Mar 14, 2020

Was there any work arounds on this, getting the same behavior. Yes we are getting an new localbind port not spec'ed. Do we spec or force that port? I thought it might have something to do with the PEM file location and how I am referencing it. I can use that Pem with three mongo remote access programs without any issues. There is NO Auth. Perhaps I have to do something in the config to state that? Any recent ideas? Thanks

@pvcon13
Copy link

pvcon13 commented Mar 14, 2020

enabled event logging and the issue is not the PEM file but a connection refused error. Not sure what parameter I have to force to make the mongo connection happy. Port is 27019 on the mongo end and 22 on the access end. Still not sure even when I try to force a localport bind which it want to override that.

status: { message: 'Create SSH Tunnel', complete: true }
status: { message: 'Connect to MongoDB', pending: true }

CONNECT ERROR ----->
_MongoClient {
_events: [Object: null prototype] {},
_eventsCount: 0,
maxListeners: undefined,
s:
{ url:
'mongodb://localhost:27019/?readPreference=primary&ssl=false',
options: { useNewUrlParser: true, useUnifiedTopology: true },
promiseLibrary: [Function: Promise],
dbCache: Map {},
sessions: Set {},
writeConcern: undefined,
namespace: MongoDBNamespace { db: 'admin', collection: undefined } } }

status: { message: 'Connect to MongoDB',
error:

_{ MongoServerSelectionError: connect ECONNREFUSED 127.0.0.1:27019
at Timeout.waitQueueMember.timer.setTimeout [as onTimeout] (/var/www/sf-platform-server-testapi/node_modules/mongodb-connection-model/node_modules/mongodb/lib/core/sdam/topology.js:430:30)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)
name: 'MongoServerSelectionError',
reason:
TopologyDescription {
type: 'Single',
setName: null,
maxSetVersion: null,
maxElectionId: null,
servers: [Map],
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: null },
[Symbol(mongoErrorContextSymbol)]: {} } }
/var/www/sf-platform-server-testapi/node_modules/mongodb-connection-model/node_modules/mongodb/lib/utils.js:725
throw error;

^

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants