例子:

以认证模式启动本地MongoDB,限定只能本地登陆,需要认证:

默认连接到本地服务器的默认端口:

以用户名’fred’和密码’foobar’连接并登录到admin数据库:

以用户名’fred’和密码’foobar’连接并登录到baz数据库:

Connect to a replica pair, with one server on example1.com and another server on example2.com:

Connect to a replica set with three servers running on localhost (on ports 27017, 27018, and 27019):

Connect to a replica set with three servers, sending all writes to the primary and distributing reads to the secondaries:

Connect to localhost with safe mode on:

Connect to a replica set with safe mode on, waiting for replication to succeed on at least two machines, with a two second timeout: