Skip to content

Instantly share code, notes, and snippets.

@george
Created August 17, 2012 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save george/3381919 to your computer and use it in GitHub Desktop.
Save george/3381919 to your computer and use it in GitHub Desktop.
ruby driver
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"}]
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