Sha256: 342f7126edae1c12e63c2d5af1327b731417327527bc8eee6994befd05604611
Contents?: true
Size: 1.37 KB
Versions: 3
Compression:
Stored size: 1.37 KB
Contents
require 'mongo' require 'mongo_request_logger/adapters/base' module MongoRequestLogger module Adapters class Mongo < Base def initialize client, opts = {} @connection = client.database @options = { read: { mode: :secondary_preferred }, write: { w: 0 } } @options.merge!(@connection.options.deep_dup) @options.merge!(opts) check_for_collection end def options @options.with_indifferent_access end def create_collection @collection = @connection[collection_name, capped: true, size: capsize] @collection.create end def create_index field @collection.indexes.create_one({ field: 1 }, background: true) end def insert_log_record(record) @collection.insert_one(record) end def collection_stats collection_stats_hash(@connection.command(collStats: collection_name).first) end def query(criteria, options={}) q = @collection.find(criteria).sort({'timestamp' => -1}) if options[:limit] q = q.limit(options[:limit]) end q end def find_by_id(id) @collection.find("_id" => ::BSON::ObjectId.from_string(id)).first end def clear! @collection.drop end end end end
Version data entries
3 entries across 3 versions & 1 rubygems