Skip to content
Browse files

readme tweaks

  • Loading branch information...
1 parent 9acc283 commit 10b5d9515e2d811cb3b554203acac8449b32de60 @PlasticLizard PlasticLizard committed Jul 12, 2011
Showing with 7 additions and 0 deletions.
  1. +7 −0 README.rdoc
View
7 README.rdoc
@@ -26,29 +26,34 @@ For operations that require IO, em-mongo always returns an EventMachine deferrab
end
#find returns an EM::Mongo::Cursor
+
cursor = collection.find
#most cursor methods return an EM::Mongo::RequestResponse,
#which is an EventMachine::Deferrable
+
resp = cursor.to_a
#when em-mongo IO methods succeed, they
#will always call back with the return
#value you would have expected from the
#synchronous version of the method from
#the mongo-ruby-driver
+
resp.callback do |documents|
puts "I just got #{documents.length} documents! I'm really cool!"
end
#when em-mongo IO methods fail, they
#errback with an array in the form
#[ErrorClass, "error message"]
+
resp.errback do |err|
raise *err
end
#iterate though each result in a query
+
collection.find( :revolution => { "$gt" => 5 } ).limit(1).skip(1).each do |doc|
#unlike the mongo-ruby-driver, each returns null at the end of the cursor
if doc
@@ -57,9 +62,11 @@ For operations that require IO, em-mongo always returns an EventMachine deferrab
end
#add an index
+
collection.create_index [[:revolution, -1]]
#insert a document and ensure it gets written
+
save_resp = collection.safe_save( { :hi => "there" }, :last_error_params => {:fsync=>true} )
save_resp.callback { puts "Hi is there, let us give thanks" }
save_resp.errback { |err| puts "AAAAAAAAAAAAAAAARGH! Oh why! WHY!?!?!" }

0 comments on commit 10b5d95

Please sign in to comment.
Something went wrong with that request. Please try again.