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

Corrupted BSON. Multiple values for same key.

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Blocker - P1 Blocker - P1
    • 12_01_17
    • Affects Version/s: 1.8.0
    • Component/s: None
    • Environment:
      Ubuntu, Mongo 2.0.4 with sharding and replica-sets, latest ruby mongo drivers.

      Here is BSON from one of our corrupted records https://raw.github.com/gist/ad402de2e594055d245e/a50138ca1e901a7b277bd174a976b4dacec5b52a/gistfile1.txt

      Our object structure (specified only broken key):

      How it should be:

      {
      ...
        'offers': {
           'last_offer': Date
           'list': [
             {...},
             {...}
           ]
        }
      ...
      }
      

      How it actually is in BSON above:

      {
      ...
        'offers': {
           'last_offer': Date
           'list': [
             {...},
             {...}
           ],
           'list': {
              '0':{ # can be any idx
                 ...
              }
           }
        }
      ...
      }
      

      YES, 2 same keys in one object with different values, in bson: `\x04list ... \x03list`. First is array and second is hash.

      Due different driver realisations mongo console returns first version, and ruby driver returns second (hash).

      I tried to run `db.collection.validate(true)` but mongo did't show errors.

      Here is our usage, that can cause it:

      We have 2 different scripts, both use ruby. One script makes $push to 'offers.list', and second script do $set on array member "offers.list.#

      {idx}". I happens in different sessions (i'm not calling $set and $push in same update).


      For some reason sometimes mongo thinks that array is empty key, and when i call $set "offers.list.#{idx}

      " it creates new version of this field which looks like "offers": {"list": { idx:

      {...}

      } }, so it creates new hash instead of modifying array.

      Frankly i cant really understand if its driver, bson gem, or mongo issue.

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            buger Leonid Bugaev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: