[SERVER-38197] How can I specify a host and path to connect to Mongo hosted on a remote server? Created: 17/Nov/18  Updated: 21/Nov/18  Resolved: 21/Nov/18

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Question Priority: Major - P3
Reporter: Daniel Montero Assignee: Danny Hatcher (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

My mongo DB is hosted a remote server is I try to connect like this:

mongo -u user -p password --host my.host.net/mongo

the client thinks that mongo is my DB when in fact is the path.

How can I specify a different path from root?



 Comments   
Comment by Danny Hatcher (Inactive) [ 21/Nov/18 ]

Hello Daniel,

Yes, that is correct. For more info, please refer to our documentation on the MongoDB Wire Protocol. I'm glad to hear everything is working fine for you now.

Have a great day,

Danny

Comment by Daniel Montero [ 21/Nov/18 ]

Hi Danny,

I think the problem is this: MongoDB uses a custom TCP wire protocol. It is not a HTTP endpoint. I exposed my the TCP port and now I'm able to connect without a problem. Thank you for you help!

Comment by Danny Hatcher (Inactive) [ 20/Nov/18 ]

Hello Daniel,

Could you provide some context on how you are trying to access MongoDB? Does the remote server's DNS resolve to my.host.net/mongo? Does it resolve to my.host.net but you are trying to do something else with /mongo?

Thank you,

Danny

Comment by Daniel Montero [ 19/Nov/18 ]

Hey Danny, I got this:

mongo -u user -p password --host my.host.net%2Fmongo
MongoDB shell version v3.6.9
connecting to: mongodb://my.host.net%252Fmongo:27017/
2018-11-19T12:33:51.997-0800 I NETWORK [thread1] getaddrinfo("my.host.net%2Fmongo") failed: Name or service not known
2018-11-19T12:33:51.998-0800 E QUERY [thread1] Error: couldn't initialize connection to host pvsdk-metrics.rose.rdlabs.hpecorp.net%2Fmongo, address is invalid :
connect@src/mongo/shell/mongo.js:257:13
@(connect):1:6
exception: connect failed

Comment by Danny Hatcher (Inactive) [ 19/Nov/18 ]

Hello Daniel,

Can you please try using percent encoding and replace the / with %2F? Your command should look like this:

mongo -u user -p password --host mongodb://my.host.net%2Fmongo

If that does not work, please provide the resulting output.

Thank you very much,

Danny

Generated at Thu Feb 08 04:48:14 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.