MongoDB C++ Driver
legacy-1.1.2
|
ConnectionString can parse MongoDB URIs with the following format: More...
#include <dbclientinterface.h>
Classes | |
class | ConnectionHook |
Public Member Functions | |
bool | sameLogicalEndpoint (const ConnectionString &other) const |
This returns true if this and other point to the same logical entity. More... | |
ConnectionString can parse MongoDB URIs with the following format:
mongodb://[usr:pwd@]host1[:port1]...[,hostN[:portN]]][/[db][?options]]
For a complete list of URI string options, see https://wiki.mongodb.com/display/DH/Connection+String+Format
Examples:
A replica set with three members (one running on default port 27017): string uri = mongodb://localhost,localhost:27018,localhost:27019
Authenticated connection to db 'bedrock' with user 'barney' and pwd 'rubble': string url = mongodb://barney:rubble/bedrock
Use parse() to parse the url, then validate and connect: string errmsg; ConnectionString cs = ConnectionString::parse( url, errmsg ); if ( ! cs.isValid() ) throw "bad connection string: " + errmsg; DBClientBase * conn = cs.connect( errmsg );
NOTE:
The 'rs_name/host1:port,host2:port' format has been deprecated, and parse() will no longer recognize this as a valid URI. To use the deprecated format, use parseDeprecated() instead.
bool mongo::ConnectionString::sameLogicalEndpoint | ( | const ConnectionString & | other | ) | const |
This returns true if this and other point to the same logical entity.
For single nodes, thats the same address. For replica sets, thats just the same replica set name. For pair (deprecated) or sync cluster connections, that's the same hosts in any ordering.