Loading...
Searching...
No Matches
Commands
Mongo Wire Protocol

Each command has an id parameter, which can be used to track replies to various commands. More...

Collaboration diagram for Commands:

## Enumerations

enum | { MONGO_WIRE_FLAG_UPDATE_UPSERT = 0x1 , MONGO_WIRE_FLAG_UPDATE_MULTI = 0x2 }
| Flags available for the update command. More...
enum | { MONGO_WIRE_FLAG_QUERY_TAILABLE_CURSOR = 1 << 1 , MONGO_WIRE_FLAG_QUERY_SLAVE_OK = 1 << 2 , MONGO_WIRE_FLAG_QUERY_NO_CURSOR_TIMEOUT = 1 << 4 , MONGO_WIRE_FLAG_QUERY_AWAIT_DATA = 1 << 5 , MONGO_WIRE_FLAG_QUERY_EXHAUST = 1 << 6 , MONGO_WIRE_FLAG_QUERY_PARTIAL_RESULTS = 1 << 7 }
| Flags available for the query command. More...
enum | { MONGO_WIRE_FLAG_DELETE_SINGLE = 0x1 }
| Flags available for the delete command. More...

## Functions

mongo_packet * | mongo_wire_cmd_update (gint32 id, const gchar *ns, gint32 flags, const bson *selector, const bson *update)
| Construct an update command.
mongo_packet * | mongo_wire_cmd_insert (gint32 id, const gchar *ns,...) G_GNUC_NULL_TERMINATED
| Construct an insert command.
mongo_packet * | mongo_wire_cmd_insert_n (gint32 id, const gchar *ns, gint32 n, const bson **docs)
| Construct an insert command with N documents.
mongo_packet * | mongo_wire_cmd_query (gint32 id, const gchar *ns, gint32 flags, gint32 skip, gint32 ret, const bson *query, const bson *sel)
| Construct a query command.
mongo_packet * | mongo_wire_cmd_get_more (gint32 id, const gchar *ns, gint32 ret, gint64 cursor_id)
| Construct a get more command.
mongo_packet * | mongo_wire_cmd_delete (gint32 id, const gchar *ns, gint32 flags, const bson *sel)
| Construct a delete command.
mongo_packet * | mongo_wire_cmd_kill_cursors (gint32 id, gint32 n,...)
| Construct a kill cursors command.
mongo_packet * | mongo_wire_cmd_custom (gint32 id, const gchar *db, gint32 flags, const bson *command)
| Construct a custom command.

## Detailed Description

Each command has an id parameter, which can be used to track replies to various commands.

It is the responsibility of the caller to keep track of IDs.

## Enumeration Type Documentation

## anonymous enum

anonymous enum

Flags available for the delete command.

Enumerator
MONGO_WIRE_FLAG_DELETE_SINGLE | Only remove the first match.

## anonymous enum

anonymous enum

Flags available for the update command.

See also
  mongo_wire_cmd_update().

Enumerator
MONGO_WIRE_FLAG_UPDATE_UPSERT | When set, inserts if no matching document was found.
MONGO_WIRE_FLAG_UPDATE_MULTI | When set, all matching documents will be updated, not just the first.

## anonymous enum

anonymous enum

Flags available for the query command.

See also
  mongo_wire_cmd_query().

Enumerator
MONGO_WIRE_FLAG_QUERY_TAILABLE_CURSOR | Set the TailableCursor flag on the query.
MONGO_WIRE_FLAG_QUERY_SLAVE_OK | Allow queries made against a replica slave.
MONGO_WIRE_FLAG_QUERY_NO_CURSOR_TIMEOUT | Disable cursor timeout.
MONGO_WIRE_FLAG_QUERY_AWAIT_DATA | Block if at the end of the data block, awaiting data. Use only with MONGO_WIRE_FLAG_QUERY_TAILABLE_CURSOR!
MONGO_WIRE_FLAG_QUERY_EXHAUST | Stream the data down full blast in multiple packages. When set, the client is not allowed not to read all the data, unless it closes connection.
MONGO_WIRE_FLAG_QUERY_PARTIAL_RESULTS | Allow partial results in a sharded environment. In case one or more required shards are down, with this flag set, partial results will be returned instead of failing.

## Function Documentation

## mongo_wire_cmd_custom()

mongo_packet * mongo_wire_cmd_custom | ( | gint32 | id,
|  | const gchar * | db,
|  | gint32 | flags,
|  | const bson * | command )

Construct a custom command.

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

Parameters

  id | is the sequence id.
  db | is the database in which the command shall be run.
  flags | are the query flags. See mongo_wire_cmd_query() for a list.
  command | is the BSON object representing the command.

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

## mongo_wire_cmd_delete()

mongo_packet * mongo_wire_cmd_delete | ( | gint32 | id,
|  | const gchar * | ns,
|  | gint32 | flags,
|  | const bson * | sel )

Construct a delete command.

Parameters

  id | is the sequence id.
  ns | is the namespace, the database and collection name concatenated, and separated with a single dot.
  flags | are the delete options. The only available flag is MONGO_WIRE_FLAG_DELETE_SINGLE.
  sel | is the BSON object to use as a selector.

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

## mongo_wire_cmd_get_more()

mongo_packet * mongo_wire_cmd_get_more | ( | gint32 | id,
|  | const gchar * | ns,
|  | gint32 | ret,
|  | gint64 | cursor_id )

Construct a get more command.

Parameters

  id | is the sequence id.
  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 packet, or NULL on error. It is the responsibility of the caller to free the packet once it is not used anymore.

## mongo_wire_cmd_insert()

mongo_packet * mongo_wire_cmd_insert | ( | gint32 | id,
|  | const gchar * | ns,
|  |  | ... )

Construct an insert command.

Parameters

  id | is the sequence id.
  ns | is the namespace, the database and collection name concatenated, and separated with a single dot.

Template Parameters

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

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

## mongo_wire_cmd_insert_n()

mongo_packet * mongo_wire_cmd_insert_n | ( | gint32 | id,
|  | const gchar * | ns,
|  | gint32 | n,
|  | const bson ** | docs )

Construct an insert command with N documents.

Parameters

  id | is the sequence id.
  ns | is the namespace, the database and collection name concatenated, and separated with a single dot.
  n | is the number of documents to insert.
  docs | is the array containing the bson documents to insert.

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

## mongo_wire_cmd_kill_cursors()

mongo_packet * mongo_wire_cmd_kill_cursors | ( | gint32 | id,
|  | gint32 | n,
|  |  | ... )

Construct a kill cursors command.

Parameters

  id | is the sequence id.
  n | is the number of cursors to delete.

Template Parameters

  cursor_ids | are the ids of the cursors to delete.

Note
  One must supply exaclty n number of cursor IDs.

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

## mongo_wire_cmd_query()

mongo_packet * mongo_wire_cmd_query | ( | gint32 | id,
|  | const gchar * | ns,
|  | gint32 | flags,
|  | gint32 | skip,
|  | gint32 | ret,
|  | const bson * | query,
|  | const bson * | sel )

Construct a query command.

Parameters

  id | is the sequence id.
  ns | is the namespace, the database and collection name concatenated, and separated with a single dot.
  flags | are the query options. Available flags are: MONGO_WIRE_FLAG_QUERY_TAILABLE_CURSOR, MONGO_WIRE_FLAG_QUERY_SLAVE_OK, MONGO_WIRE_FLAG_QUERY_NO_CURSOR_TIMEOUT, MONGO_WIRE_FLAG_QUERY_AWAIT_DATA, MONGO_WIRE_FLAG_QUERY_EXHAUST.
  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 packet, or NULL on error. It is the responsibility of the caller to free the packet once it is not used anymore.

## mongo_wire_cmd_update()

mongo_packet * mongo_wire_cmd_update | ( | gint32 | id,
|  | const gchar * | ns,
|  | gint32 | flags,
|  | const bson * | selector,
|  | const bson * | update )

Construct an update command.

Parameters

  id | is the sequence id.
  ns | is the namespace, the database and collection name concatenated, and separated with a single dot.
  flags | are the flags for the update command. Available flags are MONGO_WIRE_FLAG_UPDATE_UPSERT and MONGO_WIRE_FLAG_UPDATE_MULTI.
  selector | is the BSON document that will act as the selector.
  update | is the BSON document that contains the updated values.

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