View Source Trifle.Stats.Driver.Mongo (Trifle.Stats v2.5.0)

MongoDB driver for Trifle.Stats with Ruby gem compatibility.

Supports both joined and separated identifier modes, TTL expiration, and configurable collection names for full Ruby trifle-stats compatibility.

Summary

Functions

Link to this function

from_config(connection, config)

View Source

Create a new MongoDB driver from configuration (Ruby compatible). This applies driver_options from the configuration to override defaults.

Link to this function

inc(keys, values, driver, count \\ 1, tracking_key \\ nil)

View Source
Link to this function

new(connection, collection_name \\ "trifle_stats", separator \\ "::", write_concern \\ 1, joined_identifier \\ :full, expire_after \\ nil, system_tracking \\ true, bulk_write \\ true)

View Source

Create a new MongoDB driver instance.

Parameters

  • connection: MongoDB connection
  • collection_name: Collection name (default: "trifle_stats")
  • separator: Key separator for joined modes (default: "::")
  • write_concern: Write concern level (default: 1)
  • joined_identifier: Use joined ("full"/"partial") or separated (nil) identifiers (default: "full")
  • expire_after: TTL in seconds for automatic document expiration (default: nil)

Examples

# Basic usage
{:ok, conn} = Mongo.start_link(url: "mongodb://localhost:27017/test")
driver = Trifle.Stats.Driver.Mongo.new(conn)

# With custom options (Ruby compatible)
driver = Trifle.Stats.Driver.Mongo.new(conn, "analytics", "::", 1, :full, 86400)

# Using configuration options
config = Trifle.Stats.Configuration.configure(
  Trifle.Stats.Driver.Mongo.new(conn),
  driver_options: %{
    collection_name: "analytics_stats",
    joined_identifier: nil,
    expire_after: 86400
  }
)
Link to this function

ping(key, values, driver)

View Source
Link to this function

set(keys, values, driver, count \\ 1, tracking_key \\ nil)

View Source
Link to this function

setup!(connection, collection_name \\ "trifle_stats", joined_identifier \\ :full, expire_after \\ nil, system_tracking \\ true)

View Source

Setup MongoDB collections and indexes (Ruby compatible).

Parameters

  • connection: MongoDB connection
  • collection_name: Collection name (default: "trifle_stats")
  • joined_identifier: Index strategy - "full"/"partial" for joined, nil for separated
  • expire_after: TTL seconds for automatic expiration (default: nil)

Examples

# Basic setup (joined identifier mode)
Trifle.Stats.Driver.Mongo.setup!(conn)

# Ruby-compatible separated mode with TTL
Trifle.Stats.Driver.Mongo.setup!(conn, "analytics", nil, 86400)
Link to this function

setup_from_config!(connection, config)

View Source

Setup from configuration (convenience method).