module Utils::Mongo

Public Class Methods

create_capped_collection(collection, size, max = 10_000_000) click to toggle source
# File lib/mrpin/core/utils/mongo.rb, line 6
def create_capped_collection(collection, size, max = 10_000_000)
  Mongoid::Clients.default.command(create: collection, capped: true, size: size, max: max)
end
get_collection_data_size(collection) click to toggle source
# File lib/mrpin/core/utils/mongo.rb, line 22
def get_collection_data_size(collection)
  get_collection_stats_property(collection, 'size')
end
get_collection_stats(collection) click to toggle source
# File lib/mrpin/core/utils/mongo.rb, line 10
def get_collection_stats(collection)
  Mongoid::Clients.default.command(collStats: collection) rescue nil
end
get_collection_stats_property(collection, property) click to toggle source
# File lib/mrpin/core/utils/mongo.rb, line 26
def get_collection_stats_property(collection, property)
  result = nil

  stats = get_collection_stats(collection)

  if !stats.nil? && !stats.first.nil?
    result = stats.first[property]
  end

  result
end
get_collection_storage_size(collection) click to toggle source
# File lib/mrpin/core/utils/mongo.rb, line 18
def get_collection_storage_size(collection)
  get_collection_stats_property(collection, 'storageSize')
end
get_database_stats() click to toggle source
# File lib/mrpin/core/utils/mongo.rb, line 14
def get_database_stats
  Mongoid::Clients.default.command(dbStats: 1) rescue nil
end