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
Create a new MongoDB driver from configuration (Ruby compatible). This applies driver_options from the configuration to override defaults.
Create a new MongoDB driver instance.
Setup MongoDB collections and indexes (Ruby compatible).
Setup from configuration (convenience method).
Functions
Create a new MongoDB driver from configuration (Ruby compatible). This applies driver_options from the configuration to override defaults.
new(connection, collection_name \\ "trifle_stats", separator \\ "::", write_concern \\ 1, joined_identifier \\ :full, expire_after \\ nil, system_tracking \\ true, bulk_write \\ true)
View SourceCreate a new MongoDB driver instance.
Parameters
connection: MongoDB connectioncollection_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
}
)
setup!(connection, collection_name \\ "trifle_stats", joined_identifier \\ :full, expire_after \\ nil, system_tracking \\ true)
View SourceSetup MongoDB collections and indexes (Ruby compatible).
Parameters
connection: MongoDB connectioncollection_name: Collection name (default: "trifle_stats")joined_identifier: Index strategy - "full"/"partial" for joined, nil for separatedexpire_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)
Setup from configuration (convenience method).