连接MongoDB,认证登陆MongoDB.–php
例子:
以认证模式启动本地MongoDB,限定只能本地登陆,需要认证:
mongod -dbpath d:mongodb1.8.2db --bind_ip localhost --auth
默认连接到本地服务器的默认端口:
mongodb://localhost
以用户名’fred’和密码’foobar’连接并登录到admin数据库:
mongodb://fred:foobar@localhost
以用户名’fred’和密码’foobar’连接并登录到baz数据库:
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











