<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -235,30 +235,37 @@ module Mongo
 
     # Update a single document in this collection.
     #
-    # :spec :: a hash specifying elements which must be present for
-    #   a document to be updated
+    # :selector :: a hash specifying elements which must be present for a document to be updated. Note: 
+    # the update command currently updates only the first document matching the
+    # given selector. If you want all matching documents to be updated, be sure
+    # to specify :multi =&gt; true.
     # :document :: a hash specifying the fields to be changed in the
-    #   selected document, or (in the case of an upsert) the document to
-    #   be inserted
+    # selected document, or (in the case of an upsert) the document to
+    # be inserted
     #
     # Options:
     # :upsert :: if true, perform an upsert operation
+    # :multi :: update all documents matching the selector, as opposed to
+    # just the first matching document. Note: only works in 1.1.3 or later.
     # :safe :: if true, check that the update succeeded. OperationFailure
-    #   will be raised on an error. Checking for safety requires an extra
-    #   round-trip to the database
-    def update(spec, document, options={})
+    # will be raised on an error. Checking for safety requires an extra
+    # round-trip to the database
+    def update(selector, document, options={})
       message = ByteBuffer.new
       message.put_int(0)
       BSON.serialize_cstr(message, &quot;#{@db.name}.#{@name}&quot;)
-      message.put_int(options[:upsert] ? 1 : 0) # 1 if a repsert operation (upsert)
-      message.put_array(BSON.new.serialize(spec, false).to_a)
+      update_options  = 0
+      update_options += 1 if options[:upsert]
+      update_options += 2 if options[:multi]
+      message.put_int(update_options)
+      message.put_array(BSON.new.serialize(selector, false).to_a)
       message.put_array(BSON.new.serialize(document, false).to_a)
       if options[:safe]
         @db.send_message_with_safe_check(Mongo::Constants::OP_UPDATE, message,
-          &quot;db.#{@name}.update(#{spec.inspect}, #{document.inspect})&quot;)
+          &quot;db.#{@name}.update(#{selector.inspect}, #{document.inspect})&quot;)
       else
         @db.send_message_with_operation(Mongo::Constants::OP_UPDATE, message, 
-          &quot;db.#{@name}.update(#{spec.inspect}, #{document.inspect})&quot;)
+          &quot;db.#{@name}.update(#{selector.inspect}, #{document.inspect})&quot;)
       end
     end
 </diff>
      <filename>lib/mongo/collection.rb</filename>
    </modified>
    <modified>
      <diff>@@ -465,7 +465,7 @@ module Mongo
       end
     end
 
-    # Note: this method is a stub. Will be completed in an upcoming refactoring.
+    # Send a message to the database and wait for the response.
     def receive_message_with_operation(operation, message, log_message=nil)
       message_with_headers = add_message_headers(operation, message).to_s
       @logger.debug(&quot;  MONGODB #{log_message || message}&quot;) if @logger</diff>
      <filename>lib/mongo/db.rb</filename>
    </modified>
    <modified>
      <diff>@@ -97,6 +97,20 @@ class TestCollection &lt; Test::Unit::TestCase
     assert_equal 1, @@test.find_one(:_id =&gt; id2)[&quot;x&quot;]
   end
 
+  if @@version &gt;= &quot;1.1.3&quot;
+    def test_multi_update
+      @@test.save(&quot;num&quot; =&gt; 10)
+      @@test.save(&quot;num&quot; =&gt; 10)
+      @@test.save(&quot;num&quot; =&gt; 10)
+      assert_equal 3, @@test.count
+
+      @@test.update({&quot;num&quot; =&gt; 10}, {&quot;$set&quot; =&gt; {&quot;num&quot; =&gt; 100}}, :multi =&gt; true)
+      @@test.find.each do |doc|
+        assert_equal 100, doc[&quot;num&quot;]
+      end
+    end
+  end
+
   def test_upsert
     @@test.update({&quot;page&quot; =&gt; &quot;/&quot;}, {&quot;$inc&quot; =&gt; {&quot;count&quot; =&gt; 1}}, :upsert =&gt; true)
     @@test.update({&quot;page&quot; =&gt; &quot;/&quot;}, {&quot;$inc&quot; =&gt; {&quot;count&quot; =&gt; 1}}, :upsert =&gt; true)</diff>
      <filename>test/test_collection.rb</filename>
    </modified>
    <modified>
      <diff>@@ -38,7 +38,6 @@ class CollectionTest &lt; Test::Unit::TestCase
         op == 2001 &amp;&amp; log.include?(&quot;db.books.update&quot;)
       end
       @coll.update({}, {:title =&gt; 'Moby Dick'}, :safe =&gt; true)
-
     end
 
     should &quot;send safe insert message&quot; do</diff>
      <filename>test/unit/collection_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>f891b4ece34877b629104014aeb4cd33dd40b0df</id>
    </parent>
  </parents>
  <author>
    <name>Kyle Banker</name>
    <email>kylebanker@gmail.com</email>
  </author>
  <url>http://github.com/mongodb/mongo-ruby-driver/commit/867783c665593b77578691ed93cf7d2ebce5c860</url>
  <id>867783c665593b77578691ed93cf7d2ebce5c860</id>
  <committed-date>2009-11-05T13:08:54-08:00</committed-date>
  <authored-date>2009-11-05T13:08:54-08:00</authored-date>
  <message>Added support for multi-update (available in mongo &gt;= 1.1.3)</message>
  <tree>6c9f4be8aed5f02bf125896332917a155cca3651</tree>
  <committer>
    <name>Kyle Banker</name>
    <email>kylebanker@gmail.com</email>
  </committer>
</commit>
