Loading...
Searching...
No Matches
Mongo Client

## Macros

#define | MONGO_CONN_LOCAL -1
| Constant to signal that a connection is local (unix socket).

## Functions

mongo_connection * | mongo_connect (const char *address, int port)
| Connect to a MongoDB server.
void | mongo_disconnect (mongo_connection *conn)
| Disconnect from a MongoDB server.
gboolean | mongo_packet_send (mongo_connection *conn, const mongo_packet *p)
| Sends an assembled command packet to MongoDB.
mongo_packet * | mongo_packet_recv (mongo_connection *conn)
| Receive a packet from MongoDB.
gint32 | mongo_connection_get_requestid (const mongo_connection *conn)
| Get the last requestID from a connection object.
gboolean | mongo_connection_set_timeout (mongo_connection *conn, gint timeout)
| Set a timeout for read/write operations on a connection.

## Detailed Description

## Macro Definition Documentation

## MONGO_CONN_LOCAL

#define MONGO_CONN_LOCAL -1

Constant to signal that a connection is local (unix socket).

When passed to mongo_connect() or mongo_sync_connect() as the port parameter, it signals that the address is to be interpreted as a unix socket path, not a hostname or IP.

## Function Documentation

## mongo_connect()

mongo_connection * mongo_connect | ( | const char * | address,
|  | int | port )

Connect to a MongoDB server.

Connects to a single MongoDB server.

Parameters

  address | is the address of the server (IP or unix socket path).
  port | is the port to connect to, or MONGO_CONN_LOCAL if address is a unix socket.

Returns
  A newly allocated mongo_connection object or NULL on error. It is the responsibility of the caller to free it once it is not used anymore.

## mongo_connection_get_requestid()

gint32 mongo_connection_get_requestid | ( | const mongo_connection * | conn | ) |

Get the last requestID from a connection object.

Parameters

  conn | is the connection to get the requestID from.

Returns
  The last requestID used, or -1 on error.

## mongo_connection_set_timeout()

gboolean mongo_connection_set_timeout | ( | mongo_connection * | conn,
|  | gint | timeout )

Set a timeout for read/write operations on a connection.

On systems that support it, set a timeout for read/write operations on a socket.

Parameters

  conn | is the connection to set a timeout on.
  timeout | is the timeout to set, in milliseconds.

Returns
  TRUE on success, FALSE otherwise.

Note
  The timeout is not preserved accross reconnects, if using the Sync API, however. It only applies to the active connection, and nothing else.

## mongo_disconnect()

void mongo_disconnect | ( | mongo_connection * | conn | ) |

Disconnect from a MongoDB server.

Parameters

  conn | is the connection object to disconnect from.

Note
  This also frees up the object.

## mongo_packet_recv()

mongo_packet * mongo_packet_recv | ( | mongo_connection * | conn | ) |

Receive a packet from MongoDB.

Parameters

  conn | is the connection to use for receiving.

Returns
  A response packet, or NULL upon error.

## mongo_packet_send()

gboolean mongo_packet_send | ( | mongo_connection * | conn,
|  | const mongo_packet * | p )

Sends an assembled command packet to MongoDB.

Parameters

  conn | is the connection to use for sending.
  p | is the packet to send.

Returns
  TRUE on success, when the whole packet was sent, FALSE otherwise.