From 9b5be391ef7c373d4a6e259589779bf771ca03d8 Mon Sep 17 00:00:00 2001 From: Adrian Madrid Date: Thu, 4 Dec 2008 15:04:06 -0700 Subject: [PATCH 1/5] Added options for host and port to example --- examples/demo.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/demo.rb b/examples/demo.rb index 3f8fb12..bf159d2 100644 --- a/examples/demo.rb +++ b/examples/demo.rb @@ -3,7 +3,12 @@ require 'mongo' include XGen::Mongo::Driver -db = Mongo.new.db('ruby-mongo-demo') +host = ARGV[0] || 'localhost' +port = ARGV[1] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT + +puts "Connecting to #{host}:#{port}" + +db = Mongo.new(host, port).db('ruby-mongo-demo') coll = db.collection('test') coll.clear From a91e27132305376d31e4d4e31f4b946fb6a730cb Mon Sep 17 00:00:00 2001 From: Adrian Madrid Date: Thu, 4 Dec 2008 17:07:49 -0700 Subject: [PATCH 2/5] Renamed demo to simple --- examples/{demo.rb => simple.rb} | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) rename examples/{demo.rb => simple.rb} (89%) diff --git a/examples/demo.rb b/examples/simple.rb similarity index 89% rename from examples/demo.rb rename to examples/simple.rb index bf159d2..338ee78 100644 --- a/examples/demo.rb +++ b/examples/simple.rb @@ -7,8 +7,7 @@ host = ARGV[0] || 'localhost' port = ARGV[1] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT puts "Connecting to #{host}:#{port}" - -db = Mongo.new(host, port).db('ruby-mongo-demo') +db = Mongo.new(host, port).db('ruby-mongo-examples-simple') coll = db.collection('test') coll.clear From 5a26cfce72535c7ae428017661a220737f9bd8c1 Mon Sep 17 00:00:00 2001 From: Adrian Madrid Date: Thu, 4 Dec 2008 17:08:23 -0700 Subject: [PATCH 3/5] Added simple irb console with connection settings and ready to play with --- examples/irb.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 examples/irb.rb diff --git a/examples/irb.rb b/examples/irb.rb new file mode 100755 index 0000000..21bfbfb --- /dev/null +++ b/examples/irb.rb @@ -0,0 +1,19 @@ +#!/usr/bin/env ruby +org_argv = ARGV.dup +ARGV.clear + +require 'irb' + +$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib') +require 'mongo' + +include XGen::Mongo::Driver + +host = org_argv[0] || 'localhost' +port = org_argv[1] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT + +puts "Connecting to #{host}:#{port} on DB" +DB = Mongo.new(host, port).db('ruby-mongo-examples-irb') + +puts "Starting IRB session..." +IRB.start(__FILE__) \ No newline at end of file From cb62ae626bef17f8e48387c4257f5c8f107ae0f6 Mon Sep 17 00:00:00 2001 From: Adrian Madrid Date: Thu, 4 Dec 2008 17:08:57 -0700 Subject: [PATCH 4/5] Added a benchmark set --- examples/benchmarks.rb | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 examples/benchmarks.rb diff --git a/examples/benchmarks.rb b/examples/benchmarks.rb new file mode 100644 index 0000000..ec24307 --- /dev/null +++ b/examples/benchmarks.rb @@ -0,0 +1,36 @@ +require "rubygems" +require "benchwarmer" + +$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib') +require 'mongo' + +include XGen::Mongo::Driver + +host = ARGV[0] || 'localhost' +port = ARGV[1] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT + +puts "Connecting to #{host}:#{port}" +db = Mongo.new(host, port).db('ruby-mongo-examples-complex') +coll = db.collection('test') +coll.clear + +OBJS_COUNT = 100 +TEST_COUNT = 100 + +puts "Generating benchmark data" +msgs = %w{hola hello aloha ciao} +arr = OBJS_COUNT.times.map {|x| { :number => x, :rndm => (rand(5)+1), :msg => msgs[rand(4)] }} + +puts "Running benchmark" +Benchmark.warmer(TEST_COUNT) do + report "single object inserts" do + coll.clear + arr.each {|x| coll.insert(x)} + end + report "multiple object insert" do + coll.clear + coll.insert(arr) + end +end + +coll.clear From 453d90a68ea2bbb6b3320997f445cdb68d696657 Mon Sep 17 00:00:00 2001 From: Adrian Madrid Date: Thu, 4 Dec 2008 17:10:00 -0700 Subject: [PATCH 5/5] Added a simple check for a single array passed as the first and only parameter when inserting objects --- lib/mongo/collection.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/mongo/collection.rb b/lib/mongo/collection.rb index 7447941..5fe2f22 100644 --- a/lib/mongo/collection.rb +++ b/lib/mongo/collection.rb @@ -32,6 +32,7 @@ module XGen end def insert(*objects) + objects = objects.first if objects.size == 1 && objects.first.is_a?(Array) @db.insert_into_db(@name, objects) end