Loading...
Searching...
No Matches
Mongo Sync API
Collaboration diagram for Mongo Sync API:

## Topics

| Mongo Sync Cursor API
| Mongo Sync Pool API
| These commands implement connection pooling over the mongo_sync family of commands.
| Mongo GridFS API

## Enumerations

enum | { MONGO_COLLECTION_DEFAULTS = 0 , MONGO_COLLECTION_CAPPED = 1 << 0 , MONGO_COLLECTION_CAPPED_MAX = 1 << 1 , MONGO_COLLECTION_AUTO_INDEX_ID = 1 << 2 , MONGO_COLLECTION_SIZED = 1 << 3 }
| Flags that can be set during collection creation. More...
enum | { MONGO_INDEX_UNIQUE = 0x01 , MONGO_INDEX_DROP_DUPS = 0x02 , MONGO_INDEX_BACKGROUND = 0x04 , MONGO_INDEX_SPARSE = 0x08 }
| Flags that can be set at index creation. More...

## Functions

mongo_sync_conn_recovery_cache * | mongo_sync_conn_recovery_cache_new (void)
| Create a new connection recovery cache object.
void | mongo_sync_conn_recovery_cache_free (mongo_sync_conn_recovery_cache *cache)
| Free a connection recovery cache object.
void | mongo_sync_conn_recovery_cache_discard (mongo_sync_conn_recovery_cache *cache)
| Discards a connection recovery cache object.
gboolean | mongo_sync_conn_recovery_cache_seed_add (mongo_sync_conn_recovery_cache *cache, const gchar *host, gint port)
| Add a seed to a connection recovery cache object.
mongo_sync_connection * | mongo_sync_connect_recovery_cache (mongo_sync_conn_recovery_cache *cache, gboolean slaveok)
| Synchronously connect to a MongoDB server using an external connection recovery cache object.
mongo_sync_connection * | mongo_sync_connect (const gchar *address, gint port, gboolean slaveok)
| Synchronously connect to a MongoDB server.
gboolean | mongo_sync_conn_seed_add (mongo_sync_connection *conn, const gchar *host, gint port)
| Add a seed to an existing MongoDB connection.
mongo_sync_connection * | mongo_sync_reconnect (mongo_sync_connection *conn, gboolean force_master)
| Attempt to connect to another member of a replica set.
void | mongo_sync_disconnect (mongo_sync_connection *conn)
| Close and free a synchronous MongoDB connection.
gboolean | mongo_sync_conn_get_slaveok (const mongo_sync_connection *conn)
| Retrieve the state of the SLAVE_OK flag from a sync connection.
gboolean | mongo_sync_conn_set_slaveok (mongo_sync_connection *conn, gboolean slaveok)
| Set the SLAVE_OK flag on a sync connection.
gboolean | mongo_sync_conn_get_safe_mode (const mongo_sync_connection *conn)
| Retrieve the state of the safe mode flag from a sync connection.
gboolean | mongo_sync_conn_set_safe_mode (mongo_sync_connection *conn, gboolean safe_mode)
| Set the safe mode flag on a sync connection.
gboolean | mongo_sync_conn_get_auto_reconnect (const mongo_sync_connection *conn)
| Get the state of the auto-reconnect flag from a sync connection.
gboolean | mongo_sync_conn_set_auto_reconnect (mongo_sync_connection *conn, gboolean auto_reconnect)
| Set the state of the auto-reconnect flag on a sync connection.
gint32 | mongo_sync_conn_get_max_insert_size (mongo_sync_connection *conn)
| Get the maximum size of a bulk insert package.
gboolean | mongo_sync_conn_set_max_insert_size (mongo_sync_connection *conn, gint32 max_size)
| Set the maximum size of a bulk insert package.
gboolean | mongo_sync_cmd_update (mongo_sync_connection *conn, const gchar *ns, gint32 flags, const bson *selector, const bson *update)
| Send an update command to MongoDB.
gboolean | mongo_sync_cmd_insert (mongo_sync_connection *conn, const gchar *ns,...) G_GNUC_NULL_TERMINATED
| Send an insert command to MongoDB.
gboolean | mongo_sync_cmd_insert_n (mongo_sync_connection *conn, const gchar *ns, gint32 n, const bson **docs)
| Send an insert command to MongoDB.
mongo_packet * | mongo_sync_cmd_query (mongo_sync_connection *conn, const gchar *ns, gint32 flags, gint32 skip, gint32 ret, const bson *query, const bson *sel)
| Send a query command to MongoDB.
mongo_packet * | mongo_sync_cmd_get_more (mongo_sync_connection *conn, const gchar *ns, gint32 ret, gint64 cursor_id)
| Send a get more command to MongoDB.
gboolean | mongo_sync_cmd_delete (mongo_sync_connection *conn, const gchar *ns, gint32 flags, const bson *sel)
| Send a delete command to MongoDB.
gboolean | mongo_sync_cmd_kill_cursors (mongo_sync_connection *conn, gint32 n,...)
| Send a kill_cursors command to MongoDB.
mongo_packet * | mongo_sync_cmd_custom (mongo_sync_connection *conn, const gchar *db, const bson *command)
| Send a custom command to MongoDB.
gdouble | mongo_sync_cmd_count (mongo_sync_connection *conn, const gchar *db, const gchar *coll, const bson *query)
| Send a count() command to MongoDB.
gboolean | mongo_sync_cmd_create (mongo_sync_connection *conn, const gchar *db, const gchar *coll, gint flags,...)
| Create a new MongoDB collection.
bson * | mongo_sync_cmd_exists (mongo_sync_connection *conn, const gchar *db, const gchar *coll)
| Check whether a collection exists in MongoDB.
gboolean | mongo_sync_cmd_drop (mongo_sync_connection *conn, const gchar *db, const gchar *coll)
| Send a drop() command to MongoDB.
gboolean | mongo_sync_cmd_get_last_error (mongo_sync_connection *conn, const gchar *db, gchar **error)
| Get the last error from MongoDB.
gboolean | mongo_sync_cmd_get_last_error_full (mongo_sync_connection *conn, const gchar *db, bson **error)
| Get the last error from MongoDB.
gboolean | mongo_sync_cmd_reset_error (mongo_sync_connection *conn, const gchar *db)
| Reset the last error variable in MongoDB.
gboolean | mongo_sync_cmd_is_master (mongo_sync_connection *conn)
| Check whether the current node is the master.
gboolean | mongo_sync_cmd_ping (mongo_sync_connection *conn)
| Send a PING command to MongoDB.
gboolean | mongo_sync_cmd_user_add (mongo_sync_connection *conn, const gchar *db, const gchar *user, const gchar *pw)
| Add a user to MongoDB.
gboolean | mongo_sync_cmd_user_add_with_roles (mongo_sync_connection *conn, const gchar *db, const gchar *user, const gchar *pw, const bson *roles)
| Add a user to MongoDB, with roles.
gboolean | mongo_sync_cmd_user_remove (mongo_sync_connection *conn, const gchar *db, const gchar *user)
| Remove a user from MongoDB.
gboolean | mongo_sync_cmd_authenticate (mongo_sync_connection *conn, const gchar *db, const gchar *user, const gchar *pw)
| Authenticate a user with MongoDB.
gboolean | mongo_sync_cmd_index_create (mongo_sync_connection *conn, const gchar *ns, const bson *key, gint options)
| Create an index.
gboolean | mongo_sync_cmd_index_drop (mongo_sync_connection *conn, const gchar *ns, const bson *key)
| Drop an index.
gboolean | mongo_sync_cmd_index_drop_all (mongo_sync_connection *conn, const gchar *ns)
| Drop all indexes from a namespace.
const gchar * | mongo_sync_conn_get_last_error (mongo_sync_connection *conn)
| Get the last error message on a connection.

## Detailed Description

These commands provide wrappers for the most often used MongoDB commands.

All of these will send the command, and receive any results, thus saving the caller from having to do that himself.

However, these are only of use when blocking the application is not an issue. For asynchronous operation, one should still construct the packets himself, and send / receive when appropriate.

## Enumeration Type Documentation

## anonymous enum

anonymous enum

Flags that can be set at index creation.

Enumerator
MONGO_INDEX_UNIQUE | Create a unique index.
MONGO_INDEX_DROP_DUPS | Drop duplicate entries when creating the indexes.
MONGO_INDEX_BACKGROUND | Create indexes in the background.
MONGO_INDEX_SPARSE | Create sparse indexes.

## anonymous enum

anonymous enum

Flags that can be set during collection creation.

Enumerator
MONGO_COLLECTION_DEFAULTS | Default options.
MONGO_COLLECTION_CAPPED | The collection is capped.
MONGO_COLLECTION_CAPPED_MAX | The collection is capped by element number aswell.
MONGO_COLLECTION_AUTO_INDEX_ID | The collection's _id should be autoindexed.
MONGO_COLLECTION_SIZED | The collection needs to be pre-allocated.

## Function Documentation

## mongo_sync_cmd_authenticate()

gboolean mongo_sync_cmd_authenticate | ( | mongo_sync_connection * | conn,
|  | const gchar * | db,
|  | const gchar * | user,
|  | const gchar * | pw )

Authenticate a user with MongoDB.

Parameters

  conn | is the connection to work with.
  db | is the database to authenticate against.
  user | is the username.
  pw | is the password.

Returns
  TRUE on success, FALSE otherwise.

## mongo_sync_cmd_count()

gdouble mongo_sync_cmd_count | ( | mongo_sync_connection * | conn,
|  | const gchar * | db,
|  | const gchar * | coll,
|  | const bson * | query )

Send a count() command to MongoDB.

The count command is an efficient way to count tha available documents matching a selector.

Parameters

  conn | is the connection to work with.
  db | is the name of the database.
  coll | is the name of the collection.
  query | is the optional selector (NULL will count all documents within the collection).

Returns
  The number of matching documents, or -1 on error.

## mongo_sync_cmd_create()

gboolean mongo_sync_cmd_create | ( | mongo_sync_connection * | conn,
|  | const gchar * | db,
|  | const gchar * | coll,
|  | gint | flags,
|  |  | ... )

Create a new MongoDB collection.

This command can be used to explicitly create a MongoDB collection, with various parameters pre-set.

Parameters

  conn | is the connection to work with.
  db | is the name of the database.
  coll | is the name of the collection to create.
  flags | is a collection of flags for the collection. Any combination of MONGO_COLLECTION_DEFAULTS, MONGO_COLLECTION_CAPPED, MONGO_COLLECTION_CAPPED_MAX, MONGO_COLLECTION_SIZED and MONGO_COLLECTION_AUTO_INDEX_ID is acceptable.

Template Parameters

  size | MUST be a 64-bit integer, if MONGO_COLLECTION_CAPPED or MONGO_COLLECTION_SIZED is specified, and it must follow the flags parameter.
  max | MUST be a 64-bit integer, if MONGO_COLLECTION_CAPPED_MAX is specified, and must follow size.

Returns
  TRUE on success, FALSE otherwise.

## mongo_sync_cmd_custom()

mongo_packet * mongo_sync_cmd_custom | ( | mongo_sync_connection * | conn,
|  | const gchar * | db,
|  | const bson * | command )

Send a custom command to MongoDB.

Custom commands are queries run in the db.$cmd namespace. The commands themselves are queries, and as such, BSON objects.

Parameters

  conn | is the connection to work with.
  db | is the database in which the command shall be run.
  command | is the BSON object representing the command.

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

## mongo_sync_cmd_delete()

gboolean mongo_sync_cmd_delete | ( | mongo_sync_connection * | conn,
|  | const gchar * | ns,
|  | gint32 | flags,
|  | const bson * | sel )

Send a delete command to MongoDB.

Parameters

  conn | is the connection to work with.
  ns | is the namespace, the database and collection name concatenated, and separated with a single dot.
  flags | are the delete options. See mongo_wire_cmd_delete().
  sel | is the BSON object to use as a selector.

Returns
  TRUE on success, FALSE otherwise.

## mongo_sync_cmd_drop()

gboolean mongo_sync_cmd_drop | ( | mongo_sync_connection * | conn,
|  | const gchar * | db,
|  | const gchar * | coll )

Send a drop() command to MongoDB.

With this command, one can easily drop a collection.

Parameters

  conn | is the connection to work with.
  db | is the name of the database.
  coll | is the name of the collection to drop.

Returns
  TRUE if the collection was dropped, FALSE otherwise.

## mongo_sync_cmd_exists()

bson * mongo_sync_cmd_exists | ( | mongo_sync_connection * | conn,
|  | const gchar * | db,
|  | const gchar * | coll )

Check whether a collection exists in MongoDB.

Parameters

  conn | is the connection to work with.
  db | is the database to search for the collection.
  coll | is the collection to search for.

Returns
  A newly allocated BSON object, with data about the collection on success, NULL otherwise. It is the responsiblity of the caller to free the BSON object once it is no longer needed.

## mongo_sync_cmd_get_last_error()

gboolean mongo_sync_cmd_get_last_error | ( | mongo_sync_connection * | conn,
|  | const gchar * | db,
|  | gchar ** | error )

Get the last error from MongoDB.

Retrieves the last error from MongoDB.

Parameters

  conn | is the connection to work with.
  db | is the name of the database.
  error | is a pointer to a string variable that will hold the error message.

Returns
  TRUE if the error was succesfully retrieved, FALSE otherwise. The output variable error is only set if the function is returning TRUE.

## mongo_sync_cmd_get_last_error_full()

gboolean mongo_sync_cmd_get_last_error_full | ( | mongo_sync_connection * | conn,
|  | const gchar * | db,
|  | bson ** | error )

Get the last error from MongoDB.

Retrieves the last error from MongoDB.

Parameters

  conn | is the connection to work with.
  db | is the name of the database.
  error | is a pointer to a BSON variable that will hold the error message.

Returns
  TRUE if the error was succesfully retrieved, FALSE otherwise. The output variable error is only set if the function is returning TRUE.

## mongo_sync_cmd_get_more()

mongo_packet * mongo_sync_cmd_get_more | ( | mongo_sync_connection * | conn,
|  | const gchar * | ns,
|  | gint32 | ret,
|  | gint64 | cursor_id )

Send a get more command to MongoDB.

Parameters

  conn | is the connection to work with.
  ns | is the namespace, the database and collection name concatenated, and separated with a single dot.
  ret | is the number of documents to return.
  cursor_id | is the ID of the cursor to use.

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

## mongo_sync_cmd_index_create()

gboolean mongo_sync_cmd_index_create | ( | mongo_sync_connection * | conn,
|  | const gchar * | ns,
|  | const bson * | key,
|  | gint | options )

Create an index.

Parameters

  conn | is the connection to work with.
  ns | is the namespace to create indexes for.
  key | is the key pattern to base indexes on.
  options | are the index options.

Returns
  TRUE on success, FALSE otherwise.

## mongo_sync_cmd_index_drop()

gboolean mongo_sync_cmd_index_drop | ( | mongo_sync_connection * | conn,
|  | const gchar * | ns,
|  | const bson * | key )

Drop an index.

Parameters

  conn | is the connection to work with.
  ns | is the namespace to drop the index from.
  key | is the index pattern to drop.

Returns
  TRUE on success, FALSE otherwise.

## mongo_sync_cmd_index_drop_all()

gboolean mongo_sync_cmd_index_drop_all | ( | mongo_sync_connection * | conn,
|  | const gchar * | ns )

Drop all indexes from a namespace.

Parameters

  conn | is the connection to work with.
  ns | is the namespace whose indexes to drop.

Returns
  TRUE on success, FALSE otherwise.

## mongo_sync_cmd_insert()

gboolean mongo_sync_cmd_insert | ( | mongo_sync_connection * | conn,
|  | const gchar * | ns,
|  |  | ... )

Send an insert command to MongoDB.

Constructs and sends an insert command to MongodB.

Parameters

  conn | is the connection to work with.
  ns | is the namespace to work in.

Template Parameters

  docs | are the documents to insert. One must close the list with a NULL value.

Returns
  TRUE on success, FALSE otherwise.

## mongo_sync_cmd_insert_n()

gboolean mongo_sync_cmd_insert_n | ( | mongo_sync_connection * | conn,
|  | const gchar * | ns,
|  | gint32 | n,
|  | const bson ** | docs )

Send an insert command to MongoDB.

Constructs and sends an insert command to MongodB.

Parameters

  conn | is the connection to work with.
  ns | is the namespace to work in.
  n | is the number of documents to insert.
  docs | is the array the documents to insert. There must be at least n documents in the array.

Returns
  TRUE on success, FALSE otherwise.

## mongo_sync_cmd_is_master()

gboolean mongo_sync_cmd_is_master | ( | mongo_sync_connection * | conn | ) |

Check whether the current node is the master.

Parameters

  conn | is the connection to work with.

Returns
  TRUE if it is master, FALSE otherwise and on errors.

## mongo_sync_cmd_kill_cursors()

gboolean mongo_sync_cmd_kill_cursors | ( | mongo_sync_connection * | conn,
|  | gint32 | n,
|  |  | ... )

Send a kill_cursors command to MongoDB.

Parameters

  conn | is the connection to work with.
  n | is the number of cursors to kill.

Template Parameters

  cursor_ids | is the list of cursor ids to kill.

Note
  One must supply exaclty n number of cursor IDs.

Returns
  TRUE on success, FALSE otherwise.

## mongo_sync_cmd_ping()

gboolean mongo_sync_cmd_ping | ( | mongo_sync_connection * | conn | ) |

Send a PING command to MongoDB.

Parameters

  conn | is the connection to work with.

Returns
  TRUE if the connection is alive and kicking, FALSE otherwise.

## mongo_sync_cmd_query()

mongo_packet * mongo_sync_cmd_query | ( | mongo_sync_connection * | conn,
|  | const gchar * | ns,
|  | gint32 | flags,
|  | gint32 | skip,
|  | gint32 | ret,
|  | const bson * | query,
|  | const bson * | sel )

Send a query command to MongoDB.

Parameters

  conn | is the connection to work with.
  ns | is the namespace, the database and collection name concatenated, and separated with a single dot.
  flags | are the query options. See mongo_wire_cmd_query().
  skip | is the number of documents to skip.
  ret | is the number of documents to return.
  query | is the query BSON object.
  sel | is the (optional) selector BSON object indicating the fields to return. Passing NULL will return all fields.

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

## mongo_sync_cmd_reset_error()

gboolean mongo_sync_cmd_reset_error | ( | mongo_sync_connection * | conn,
|  | const gchar * | db )

Reset the last error variable in MongoDB.

Parameters

  conn | is the connection to work with.
  db | is the name of the database.

Returns
  TRUE on success, FALSE otherwise.

## mongo_sync_cmd_update()

gboolean mongo_sync_cmd_update | ( | mongo_sync_connection * | conn,
|  | const gchar * | ns,
|  | gint32 | flags,
|  | const bson * | selector,
|  | const bson * | update )

Send an update command to MongoDB.

Constructs and sends an update command to MongoDB.

Parameters

  conn | is the connection to work with.
  ns | is the namespace to work in.
  flags | are the flags for the update command. See mongo_wire_cmd_update().
  selector | is the BSON document that will act as the selector.
  update | is the BSON document that contains the updated values.

Returns
  TRUE on success, FALSE otherwise.

## mongo_sync_cmd_user_add()

gboolean mongo_sync_cmd_user_add | ( | mongo_sync_connection * | conn,
|  | const gchar * | db,
|  | const gchar * | user,
|  | const gchar * | pw )

Add a user to MongoDB.

Parameters

  conn | is the connection to work with.
  db | is the database to add the user to.
  user | is the user to add.
  pw | is the password.

Returns
  TRUE on success, FALSE otherwise.

## mongo_sync_cmd_user_add_with_roles()

gboolean mongo_sync_cmd_user_add_with_roles | ( | mongo_sync_connection * | conn,
|  | const gchar * | db,
|  | const gchar * | user,
|  | const gchar * | pw,
|  | const bson * | roles )

Add a user to MongoDB, with roles.

Parameters

  conn | is the connection to work with.
  db | is the database to add the user to.
  user | is the user to add.
  pw | is the password.
  roles | is a BSON array containing the roles for the user.

Returns
  TRUE on success, FALSE otherwise.

## mongo_sync_cmd_user_remove()

gboolean mongo_sync_cmd_user_remove | ( | mongo_sync_connection * | conn,
|  | const gchar * | db,
|  | const gchar * | user )

Remove a user from MongoDB.

Parameters

  conn | is the connection to work with.
  db | is the database to remove the user from.
  user | is the username to remove.

Returns
  TRUE on success, FALSE otherwise.

## mongo_sync_conn_get_auto_reconnect()

gboolean mongo_sync_conn_get_auto_reconnect | ( | const mongo_sync_connection * | conn | ) |

Get the state of the auto-reconnect flag from a sync connection.

Parameters

  conn | is the connection to check the flag on.

Returns
  The state of the auto-reconnect flag.

## mongo_sync_conn_get_last_error()

const gchar * mongo_sync_conn_get_last_error | ( | mongo_sync_connection * | conn | ) |

Get the last error message on a connection.

Parameters

  conn | is the connection

Returns
  pointer to the error message, if exists, NULL otherwise

## mongo_sync_conn_get_max_insert_size()

gint32 mongo_sync_conn_get_max_insert_size | ( | mongo_sync_connection * | conn | ) |

Get the maximum size of a bulk insert package.

Parameters

  conn | is the connection to get the maximum size from.

Returns
  The maximum size, or -1 on failiure.

## mongo_sync_conn_get_safe_mode()

gboolean mongo_sync_conn_get_safe_mode | ( | const mongo_sync_connection * | conn | ) |

Retrieve the state of the safe mode flag from a sync connection.

Parameters

  conn | is the connection to check the flag on.

Returns
  The state of the safe mode flag.

## mongo_sync_conn_get_slaveok()

gboolean mongo_sync_conn_get_slaveok | ( | const mongo_sync_connection * | conn | ) |

Retrieve the state of the SLAVE_OK flag from a sync connection.

Parameters

  conn | is the connection to check the flag on.

Returns
  The state of the SLAVE_OK flag.

## mongo_sync_conn_recovery_cache_discard()

void mongo_sync_conn_recovery_cache_discard | ( | mongo_sync_conn_recovery_cache * | cache | ) |

Discards a connection recovery cache object.

Parameters

  cache | is the recovery cache object

## mongo_sync_conn_recovery_cache_free()

void mongo_sync_conn_recovery_cache_free | ( | mongo_sync_conn_recovery_cache * | cache | ) |

Free a connection recovery cache object.

Parameters

  cache | is the recovery cache object

## mongo_sync_conn_recovery_cache_new()

mongo_sync_conn_recovery_cache * mongo_sync_conn_recovery_cache_new | ( | void |  | ) |

Create a new connection recovery cache object.

Returns
  the newly created recovery cache object

## mongo_sync_conn_recovery_cache_seed_add()

gboolean mongo_sync_conn_recovery_cache_seed_add | ( | mongo_sync_conn_recovery_cache * | cache,
|  | const gchar * | host,
|  | gint | port )

Add a seed to a connection recovery cache object.

The seed list will be used for reconnects, prioritized before the automatically discovered host list.

Parameters

  cache | is the connection recovery cache to add a seed to.
  host | is the seed host to add.
  port | is the seed's port.

Returns
  TRUE on success, FALSE otherwise.

## mongo_sync_conn_seed_add()

gboolean mongo_sync_conn_seed_add | ( | mongo_sync_connection * | conn,
|  | const gchar * | host,
|  | gint | port )

Add a seed to an existing MongoDB connection.

The seed list will be used for reconnects, prioritized before the automatically discovered host list.

Parameters

  conn | is the connection to add a seed to.
  host | is the seed host to add.
  port | is the seed's port.

Returns
  TRUE on success, FALSE otherwise.

## mongo_sync_conn_set_auto_reconnect()

gboolean mongo_sync_conn_set_auto_reconnect | ( | mongo_sync_connection * | conn,
|  | gboolean | auto_reconnect )

Set the state of the auto-reconnect flag on a sync connection.

When auto-reconnect is enabled, the library will automatically attempt to reconnect to a server behind the scenes, when it detects an error.

If safe-mode is turned on aswell, then auto-reconnect will only happen if the error is detected before a command is sent towards the database.

Parameters

  conn | is the connection to set auto-reconnect on.
  auto_reconnect | is the state to set it to.

Returns
  TRUE on success, FALSE otherwise.

## mongo_sync_conn_set_max_insert_size()

gboolean mongo_sync_conn_set_max_insert_size | ( | mongo_sync_connection * | conn,
|  | gint32 | max_size )

Set the maximum size of a bulk insert package.

When inserting multiple documents at a time, the library can automatically split the pack up into smaller chunks. With this function, one can set the maximum size, past which, the request will be split into smaller chunks.

Parameters

  conn | is the connection to set the maximum size for.
  max_size | is the maximum size, in bytes.

Returns
  TRUE on success, FALSE otherwise.

## mongo_sync_conn_set_safe_mode()

gboolean mongo_sync_conn_set_safe_mode | ( | mongo_sync_connection * | conn,
|  | gboolean | safe_mode )

Set the safe mode flag on a sync connection.

Enabling safe mode will result in an additional getLastError() call after each insert or update, and extra checks performed on other commands aswell.

The upside is more guarantees that the commands succeed, at the expense of network traffic and speed.

Parameters

  conn | is the connection to set the flag on.
  safe_mode | is the state to set it to.

Returns
  TRUE on success, FALSE otherwise.

## mongo_sync_conn_set_slaveok()

gboolean mongo_sync_conn_set_slaveok | ( | mongo_sync_connection * | conn,
|  | gboolean | slaveok )

Set the SLAVE_OK flag on a sync connection.

Parameters

  conn | is the connection to set the flag on.
  slaveok | is the state to set.

Returns
  TRUE on sucess, FALSE otherwise.

## mongo_sync_connect()

mongo_sync_connection * mongo_sync_connect | ( | const gchar * | address,
|  | gint | port,
|  | gboolean | slaveok )

Synchronously connect to a MongoDB server.

Sets up a synchronous connection to a 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.
  slaveok | signals whether queries made against a slave are acceptable.

Returns
  A newly allocated mongo_sync_connection object, or NULL on error. It is the responsibility of the caller to close and free the connection when appropriate.

## mongo_sync_connect_recovery_cache()

mongo_sync_connection * mongo_sync_connect_recovery_cache | ( | mongo_sync_conn_recovery_cache * | cache,
|  | gboolean | slaveok )

Synchronously connect to a MongoDB server using an external connection recovery cache object.

Sets up a synchronous connection to a MongoDB server.

Parameters

  cache | is the externally managed connection recovery cache object.
  slaveok | signals whether queries made against a slave are acceptable.

Returns
  A newly allocated mongo_sync_connection object, or NULL on error. It is the responsibility of the caller to close and free the connection when appropriate.

## mongo_sync_disconnect()

void mongo_sync_disconnect | ( | mongo_sync_connection * | conn | ) |

Close and free a synchronous MongoDB connection.

Parameters

  conn | is the connection to close.

Note
  The object will be freed, and shall not be used afterwards!

## mongo_sync_reconnect()

mongo_sync_connection * mongo_sync_reconnect | ( | mongo_sync_connection * | conn,
|  | gboolean | force_master )

Attempt to connect to another member of a replica set.

Given an existing connection, this function will try to connect to an available node (enforcing that it's a primary, if asked to) by trying all known hosts until it finds one available.

Parameters

  conn | is an existing MongoDB connection.
  force_master | signals whether a primary node should be found.

Returns
  A mongo_sync_collection object, or NULL if the reconnect fails for one reason or the other.

Note
  The original connection object will be updated too!