Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-341

Lastest Mongoid updates all attributes on save.

    • Type: Icon: Task Task
    • Resolution: Done
    • 12_01_17
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      One of the reason I switched over to mongoid is that is performed atomic updates correctly. If I update one field, it should only run an update to the DB with one field, not all fields. this helps prevent overwrites from occurring in concurrent systems.

      But with the current version of Mongoid (beta18) I'm seeing this no longer the case. For example.

      I create a record where the insert looks like this.

      MONGODB test_db['locations'].insert(
      [
      {
      "_id"=>BSON::ObjectID('4c939ed120252cb5d30000ff'),
      "name"=>"Other Music Inc",
      "url"=>"http://maps.google.com/maps/place?cid=6583927858764579749",
      "geo_location"=>

      { "_id"=>BSON::ObjectID('4c939ed120252cb5d3000100'), "lat"=>42.185842, "lng"=>-87.80046 }

      ,
      "address"=>

      { "_id"=>BSON::ObjectID('4c939ed120252cb5d3000101'), "city"=>"San Francisco", "region"=>"IL", "street"=>"620 Central Avenue", "postal_code"=>"60035", "country"=>"United States" }

      ,
      "created_at"=>2010-09-17 17:01:05 UTC,
      "updated_at"=>2010-09-17 17:01:05 UTC
      }
      ]
      )

      And then I do the following on a mongoid object.

      location.contact_email = "someone@interested.com"
      location.token = "3c842fc1100b235116993dca21ac741c8f6e90c2"
      location.token_xpr = Time.now.utc + 30.days
      location.events << update_event
      location.save

      I see this gets run to the DB

      MONGODB test_db['locations'].update(

      {"_id"=>BSON::ObjectID('4c939ed120252cb5d30000ff')}

      ,
      {
      "$set"=>

      { "token_xpr"=>2010-10-17 23:59:59 UTC, "token"=>"3c842fc1100b235116993dca21ac741c8f6e90c2", "contact_email"=>"someone@interested.com", "geo_location.lat"=>42.185842, "geo_location.lng"=>-87.80046, "address.city"=>"San Francisco", "address.region"=>"IL", "address.street"=>"620 Central Avenue", "address.postal_code"=>"60035", "address.country"=>"United States" }

      ,
      "$pushAll" => {
      "events"=>[
      {
      "edits"=>

      { "contact_email"=>[nil, "someone@interested.com"]}

      ,
      "info"=>"Invite contact 'someone@interested.com'",
      "created_at"=>2010-09-17 17:01:05 UTC,
      "_id"=>BSON::ObjectID('4c939ed120252cb5d3000102'),
      "_type"=>"UpdateEvent"
      }
      ]
      }
      }
      )

      It seems to be putting all the attributes back into the record. Why would this be happening?

            Assignee:
            Unassigned Unassigned
            Reporter:
            squarelover Sean Wolfe
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: