Module: Utils::Mongo
- Defined in:
- lib/mrpin/core/utils/mongo.rb
Class Method Summary collapse
- .create_capped_collection(collection, size, max = 10_000_000) ⇒ Object
- .get_collection_data_size(collection) ⇒ Object
- .get_collection_stats(collection) ⇒ Object
- .get_collection_stats_property(collection, property) ⇒ Object
- .get_collection_storage_size(collection) ⇒ Object
- .get_database_stats ⇒ Object
Class Method Details
.create_capped_collection(collection, size, max = 10_000_000) ⇒ Object
6 7 8 |
# 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) ⇒ Object
22 23 24 |
# 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) ⇒ Object
10 11 12 |
# 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) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# 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) ⇒ Object
18 19 20 |
# 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 ⇒ Object
14 15 16 |
# File 'lib/mrpin/core/utils/mongo.rb', line 14 def get_database_stats Mongoid::Clients.default.command(dbStats: 1) rescue nil end |