|
MongoDB is a database server: it runs in the foreground or background and waits for connections from the user. Thus, when you start MongoDB, you will see something like: ~/$ ./mongod # # some logging output # Tue Mar 9 11:15:43 waiting for connections on port 27017 Tue Mar 9 11:15:43 web admin interface listening on port 28017 It will stop printing output at this point but it hasn't frozen, it is merely waiting for connections on port 27017. Once you connect and start sending commands, it will continue to log what it's doing. You can use any of the MongoDB drivers or Mongo shell to connect to the database. You cannot connect to MongoDB by going to http://localhost:27017 in your web browser. The database cannot be accessed via HTTP on port 27017. Standard Connection String Format
mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]
As many hosts as necessary may be specified (for connecting to replica pairs/sets). The options are: Replica set:
Single server:
Any configuration:
These options are not case sensitive. ExamplesConnect to a database server running locally on the default port: mongodb://localhost
Connect and login to the admin database as user "fred" with password "foobar": mongodb://fred:foobar@localhost
Connect and login to the "baz" database as user "fred" with password "foobar": mongodb://fred:foobar@localhost/baz
Connect to a replica pair, with one server on example1.com and another server on example2.com: mongodb://example1.com:27017,example2.com:27017
Connect to a replica set with three servers running on localhost (on ports 27017, 27018, and 27019): mongodb://localhost,localhost:27018,localhost:27019
Connect to a replica set with three servers, sending all writes to the primary and distributing reads to the secondaries: mongodb://host1,host2,host3/?slaveOk=true
Connect to localhost with safe mode on: mongodb://localhost/?safe=true
Connect to a replica set with safe mode on, waiting for replication to succeed on at least two machines, with a two second timeout: mongodb://host1,host2,host3/?safe=true;w=2;wtimeoutMS=2000
Connection Pooling
|

PLEASE POST QUESTIONS IN THE FORUMS: http://groups.google.com/group/mongodb-user. Post tips and clarifications here.
blog comments powered by Disqus