Skip to content

Instantly share code, notes, and snippets.

@jhancock
Created August 13, 2009 07:11
Show Gist options
  • Save jhancock/167027 to your computer and use it in GitHub Desktop.
Save jhancock/167027 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'mongo'
require 'pp'
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
puts "Connecting to #{host}:#{port}"
db = XGen::Mongo::Driver::Mongo.new(host, port).db('jon')
coll = db.collection('test')
puts
puts ">> clear collection jon:test"
coll.clear
puts "Count of jon:test #{coll.count}"
puts
puts ">> insert an OrderedHash with attributes sample1 and when"
object = OrderedHash['sample1' => "hello", 'when' => Time.now]
pp object
oid = coll.save(object)
puts "returned ObjectID"
pp oid
puts "all objects"
coll.find().each { |doc| puts doc.inspect }
puts
puts ">> insert a new object using the save to create the hash"
oid = coll.save({'sample1' => "hello", 'when' => Time.now})
puts "returned ObjectID"
pp oid
puts "all objects"
coll.find().each { |doc| puts doc.inspect }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment