Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-1099

Bulk Updates : update_one doesn't work

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 12_01_17
    • Affects Version/s: 2.1.0
    • Component/s: None
    • Labels:
      None
    • Environment:
      ruby (2.1.7)
      mongo (2.1.0)
      mongoid (5.0.0)

      Please read the following and notice that bulk update `find` doesn't even
      match a document when `upsert => false`. Also notice with `upsert=>true` it does match a document but doesn't update the `products`. Doesn't make any sense. Is there a workaround?

      2.1.7 :001 > class Something

      2.1.7 :002?> include Mongoid::Document

      2.1.7 :003?> field :products, :type => Array

      2.1.7 :004?> end

      => #<Mongoid::Fields::Standard:0x007f83b4e075b0 @name="products", @options={:type=>Array, :klass=>Something}, @label=nil, @default_val=nil>

      2.1.7 :006 > Something.delete_all

      => 0

      2.1.7 :007 > Something.create :products => [1,2,3,4]

      => #<Something _id: 56ddec0464b1f31186000000, products: [1, 2, 3, 4]>

      2.1.7 :008 > Something.first

      => #<Something _id: 56ddec0464b1f31186000000, products: [1, 2, 3, 4]>

      2.1.7 :009 > Something.mongo_client[:something].bulk_write([{ :update_one => { :filter =>

      { "_id" => BSON::ObjectId("56ddec0464b1f31186000000")}

      , :update => {"$set" => {"products"=>[6,7]}}, :upsert => false } }])

      => #<Mongo::BulkWrite::Result:0x007f83b1e4eb48 @results=

      {"n_modified"=>0, "n_upserted"=>0, "n_matched"=>0, "n"=>0, "upserted_ids"=>[]}

      >

      2.1.7 :011 > Something.mongo_client[:something].bulk_write([{ :update_one => { :filter =>

      { "_id" => BSON::ObjectId("56ddec0464b1f31186000000")}

      , :update => {"$set" => {"products"=>[6,7]}}, :upsert => true } }])

      => #<Mongo::BulkWrite::Result:0x007f83b1d5eff8 @results=

      {"n_modified"=>0, "n_upserted"=>1, "n_matched"=>0, "n"=>1, "upserted_ids"=>[BSON::ObjectId('56ddec0464b1f31186000000')]}

      >

      2.1.7 :012 >

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            anidps@gmail.com Anirvana Mishra
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: