Created
August 13, 2009 07:11
-
-
Save jhancock/167027 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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