Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-51383

bsonWoCompare on embedded documents/objects does not match ordering described in documentation

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 4.2.9
    • Component/s: Index Maintenance, Querying
    • None
    • ALL

      According to https://docs.mongodb.com/manual/reference/bson-type-comparison-order/#objects objects are compared field-by-field (in order that they're stored):
      1. by field key name
      2. by field value

      I ran into some issues with some queries and after some research, I have some interesting results from bsonWoCompare:

      > bsonWoCompare({foo: 0}, {bar: 1})
      1
      > bsonWoCompare({foo: 0}, {bar: "BAR"})
      -5
      > bsonWoCompare({foo: true}, {bar: "BAR"})
      25
      > bsonWoCompare({foo: ""}, {bar: "BAR"})
      1
      > bsonWoCompare({foo: MinKey()}, {bar: "BAR"})
      -16
      > bsonWoCompare({foo: MaxKey()}, {bar: "BAR"})
      112
      

      Since "foo" > "bar", shouldn't bsonWoCompare always return a positive result, regardless of field values?

       

            Assignee:
            eric.sedor@mongodb.com Eric Sedor
            Reporter:
            crunk1@gmail.com Scott Crunkleton
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: