Im reading the mongodb guide, but I dont get this:
mongodb://fred:foobar@localhost
It says I can connect to the mongodb through web browser.
I have tried this, but it doesn't work. Safari/Firefox can't recognize the mongodb protocol.
And why should I do it?
Isn't the mongodb server just for connecting through the command line?
And what is the difference between port 27017 and 28017?
Should I connect through http or mongodb protocol?
Without any arguments, the mongo command attempts to connect to a local MongoDB instance. To do this, it attempts to connect to port 27017 on the local loopback address: 127.0. 0.1:27017 .
To access the http interface an administrator may, for example, point a browser to http://localhost:28017 if mongod is running with the default port on the local machine.
When you start mongod (the MongoDB daemon), it starts listening on two ports by default.
What you've listed mongodb://fred:foobar@localhost
actually represents this: mongodb://fred:foobar@localhost:27017
and this is the access protocol for MongoDB drivers.
The other "thing" you're seeing is port 28017. This is (by default) simply an overview of what's happening with the mongod
instance on that server. Requests made from a web browser to this port will show an HTML output of the server overview.
If you start mongod
with a different port number (i.e.: 7777), the "monitor" port will always be 1000 higher (i.e.: 8777).
If you want some advanced features like the ability to query via the web browser, you can start mongod
with the --rest
switch. You will then be able to run certain queries with a simple http get requestlink text (http://localhost:8777/mydb/mycollection/?filter_a=1
).
If you're using language-specific MongoDB drivers (like most people will). Then you'll find that you'll have "connection strings" of the form mongodb://user:pwd@host:port/
. These are similar in purpose to the usual connection strings you're used to for other Database products.
Increment by one thousand (28017), and use HTTP, not mongodb.
Note that this will "connect" you to the mongodb process, but it's not like phpMyAdmin or anything.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With