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

Add function to mongo shell for converting BSONObj to Array

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 4.3.1
    • Component/s: Shell
    • Labels:
      None

      Description

      The purpose of this function is to make it possible to convert the object

      {"": 1, "": 2}
      

      for sort keys returned by compound sort specifications into the array

      [1, 2]
      

      which can be meaningfully interacted with via JavaScript. The duplicate empty string field names in the object form are otherwise hidden by the first one. It should be possible to use this function on Objects which have non-duplicate and non-empty field names as well. In those cases, it can be thought of as a function similar to Object.values() but one that actually works for BSONInfo instances.

      We can model this function off the bsonWoCompare() and bsonBinaryEqual() functions where the mongo shell will define a bsonObjToArray() global function that uses ObjectWrapper::toBSON() to convert/extract the argument as a BSONObj. It should then use ValueReader::fromBSONArray() to convert the BSONObj into a JavaScript Array.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: