Class Poco::MongoDB::Connection
Author: Applied Informatics Software Engineering GmbH and Contributors

# Poco::MongoDB

# class Connection

Library: MongoDB
Package: MongoDB
Header: Poco/MongoDB/Connection.h

## Description

Represents a connection to a MongoDB server

## Member Summary

Member Functions: address, connect, disconnect, sendRequest

## Types

### Ptr

typedef Poco::SharedPtr < Connection > Ptr;

## Constructors

### Connection

Connection();

Default constructor. Use this when you want to connect later on.

### Connection

Connection(
const std::string & hostAndPort
);

Constructor which connects to the given MongoDB host/port. The host and port must be separated with a colon.

### Connection

Connection(
const Net::SocketAddress & addrs
);

Constructor which connects to the given MongoDB host/port.

### Connection

Connection(
const std::string & host,
int port
);

Constructor which connects to the given MongoDB host/port.

## Destructor

### ~Connection

virtual ~Connection();

Destructor

## Member Functions

### address

Net::SocketAddress address() const;

Returns the address of the MongoDB connection

### connect

void connect(
const std::string & hostAndPort
);

Connects to the given MongoDB server. The host and port must be separated with a colon.

### connect

void connect(
const std::string & host,
int port
);

Connects to the given MongoDB server.

### connect

void connect(
const Net::SocketAddress & addrs
);

Connects to the given MongoDB server.

### disconnect

void disconnect();

Disconnects from the MongoDB server

### sendRequest

void sendRequest(
RequestMessage & request
);

Sends a request to the MongoDB server Only use this when the request hasn't a response.

### sendRequest

void sendRequest(
RequestMessage & request,
ResponseMessage & response
);

Sends a request to the MongoDB server and receives the response. Use this when a response is expected: only a query or getmore request will return a response.