Created
August 17, 2012 19:41
-
-
Save george/3381919 to your computer and use it in GitHub Desktop.
ruby driver
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
| created course_id: 502e9ddf1a78a98345000001 | |
| new_course: | |
| {"_id"=>BSON::ObjectId('502e9ddf1a78a98345000001'), "title"=>"A New Course", "sections"=>[{"id"=>"502e73121a78a97c69000001", "title"=>"One"}, {"id"=>"502e731b1a78a97c69000002", "title"=>"Two"}]} | |
| sections: | |
| [{"id"=>"502e73121a78a97c69000001", "title"=>"One"}, {"id"=>"502e731b1a78a97c69000002", "title"=>"Two"}] | |
| ================================== | |
| the_course['_id']: 502e9ddf1a78a98345000001 | |
| the_course: | |
| {"_id"=>BSON::ObjectId('502e9ddf1a78a98345000001'), "title"=>"A New Course UPDATED", "sections"=>[{"id"=>"502e73121a78a97c69000001", "title"=>"Uno"}, {"id"=>"502e731b1a78a97c69000002", "title"=>"Dos"}]} | |
| sections: | |
| [{"id"=>"502e73121a78a97c69000001", "title"=>"Uno"}, {"id"=>"502e731b1a78a97c69000002", "title"=>"Dos"}] |
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' | |
| DB = Mongo::Connection.new.db('topsoil_test') | |
| COURSES = DB.collection('courses') | |
| initial_course_doc = { | |
| title: 'A New Course', | |
| sections: [ {'id' => '502e73121a78a97c69000001', 'title' => 'One' }, | |
| {'id' => '502e731b1a78a97c69000002', 'title' => 'Two' } ] | |
| } | |
| updated_course_doc = { | |
| title: 'A New Course UPDATED', | |
| sections: [ {'id' => '502e73121a78a97c69000001', 'title' => 'Uno' }, | |
| {'id' => '502e731b1a78a97c69000002', 'title' => 'Dos' } ] | |
| } | |
| course_id = COURSES.insert(initial_course_doc) | |
| new_course = COURSES.find_one(course_id) | |
| puts <<-EOS | |
| created course_id: #{ course_id } | |
| new_course: | |
| #{ new_course } | |
| sections: | |
| #{ new_course['sections'] } | |
| ================================== | |
| EOS | |
| COURSES.update({ _id: course_id }, updated_course_doc) | |
| the_course = COURSES.find_one(course_id) | |
| puts <<-EOS | |
| the_course['_id']: #{ the_course['_id'] } | |
| the_course: | |
| #{ the_course } | |
| sections: | |
| #{ the_course['sections'] } | |
| EOS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment