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

XMLWordPrintableJSON

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

      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
            Reporter:
            Scott Crunkleton
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: