Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting default host address for mongo client

Tags:

mongodb

Each time I connect to a remote mongodb server, it is needed to write the host address of the mongo server.

In my situation, I connect only a single remote mongo. So, is there a way to set the default server address that make it possible to connect without passing host parameter each time?

like image 527
Muatik Avatar asked Jul 05 '13 08:07

Muatik


People also ask

What is MongoDB localhost URL?

connect('mongodb://localhost:27017/myapp'); This is the minimum needed to connect the myapp database running locally on the default port (27017). If connecting fails on your machine, try using 127.0. 0.1 instead of localhost .

What is the default database path for MongoDB?

The default dbpath for mongodb is /data/db .

What is hostname in MongoDB?

hostname — the IP address of the MongoDB Server and the port number that the MongoDB service uses. ▪ username — the admin user name that you created to log in to the MongoDB Server. ▪ password — the admin password used to log in to the MongoDB Server.

How do I find my MongoDB server IP address?

To find the public IP address for any node in your cluster, use the nslookup tool from the command line. The IP address is shown in the Address portion of the output.


Video Answer


2 Answers

If you are on a *nix os you can use alias (http://en.wikipedia.org/wiki/Alias_(command)):

alias mongo='mongo --host 127.0.0.1'

You might want to call you alias something else than mongo though.

like image 130
Robert Kajic Avatar answered Oct 13 '22 07:10

Robert Kajic


For the php driver, I can change the directive 'mongo.default_host = localhost' to 'mogno.default_host = REMOTEADDRESS'. By this change I no longer need to pass the host address. This is what I was looking for.

like image 44
2 revs Avatar answered Oct 13 '22 07:10

2 revs