Skip to content

Creating Capped Collections using Ruby – Sample Program

August 18, 2015

require ‘mongo’

begin

client = Mongo::Client.new([ ‘<hostname/ip>:<port>’ ],:database => ‘<databasename>’, :user => ‘<username>’, :password =>'<passwprd>’)

collection_name = {

“COLLECTION1” => 1610612736,
“COLLECTION2” => 1610612736 #SIZE in bytes (Here it is 1.5G)
}

collection_name.each do |collectionValue|
collectionDetail = client[collectionValue[0], :capped => true, :size =>collectionValue[1]]
collectionDetail.create
end

end

end

Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: