Mongo.Pool behaviour

Defines a pool of MongoDB connections.

A pool can be defined as:

defmodule MyPool do
  use Mongo.Pool,
    adapter: Mongo.Pool.Poolboy,
    hostname: "localhost"
 end

Options will be passed to the pool adapter and to Mongo.Connection.

Logging

The pool may define a log/5 function, that will be called by the driver on every call to the database.

Please refer to the callback’s documentation for more information.

Source

Summary

run_with_log(pool, log, args, opts, fun)

Invokes given pool’s run/1 gathering information necessary for the pools log/5 function

Types

t :: module

time :: integer

operation :: :run_command | :insert_one | :insert_many | :delete_one | :delete_many | :replace_one | :update_one | :update_many | :find_cursor | :find_batch | :kill_cursors

Functions

run_with_log(pool, log, args, opts, fun)

Invokes given pool’s run/1 gathering information necessary for the pools log/5 function.

The opts argument is appended to the args list passed to the pool’s log function.

Options

  • :log - if false the log/5 function won’t be invoked (default: true)
Source

Callbacks

log/5

Specs:

  • log(return, queue_time, query_time, operation, args :: list) :: return when queue_time: time, query_time: time, return: var

Called every time when the driver has a logging information to be printed.

The first argument result can be of form: :ok, {:ok, _} or {:error, _}. The second element of the tuples should be considered private, and not used.

Operations

The fourth argument determines the operation, these can be (listed with the arguments passed as the fifth argument to the log function):

OperationArguments
:run_command[query, options]
:insert_one[collection, document, options]
:insert_many[collection, documents, options]
:delete_one[collection, filter, options]
:delete_many[collection, filter, options]
:replace_one[collection, filter, replacement, options]
:update_one[collection, filter, update, options]
:update_many[collection, filter, update, options]
:find[collection, query, projection, options]
:find_rest[collection, cursor, options]
:kill_cursors[cursors, options]
Source
run/1

Specs:

  • run((pid -> return)) :: {queue_time :: time, return} when return: var

Executes given function checking out a connection from pool, and ensuring it will be properely checked in back once finished.

Source
version/0

Specs:

  • version :: non_neg_integer

Returns the version of the MongoDB wire protocol used for the pool’s connections

Source