Uploaded image for project: 'MongoDB Shell'
  1. MongoDB Shell
  2. MONGOSH-1265

`ObjectId.valueOf()`, `ObjectId.toString()` and `ObjectId.str` differs from the docs

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Minor - P4 Minor - P4
    • No version
    • Affects Version/s: 1.5.0
    • Component/s: Bson
    • None
    • Needed
    • Hide

      Need to document that these ObjectId methods behave differently from the legacy shell. The mongocompat snippet brings back some of the legacy shell behavior.

      Show
      Need to document that these ObjectId methods behave differently from the legacy shell. The mongocompat snippet brings back some of the legacy shell behavior.

      Problem Statement/Rationale

      As per docs https://www.mongodb.com/docs/manual/reference/method/ObjectId/

      ObjectId.str should be a hexadecimal string representation of the object but is undefined.

      ObjectId.valueOf() should return ObjectId.str but returns self.

      ObjectId.toString() should return a ObjectId("HEX") string but returns a HEX string.
       

      Steps to Reproduce

      F:\Workspace>mongosh
      Current Mongosh Log ID: 62c9a46047cd15a19415dc03
      Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.5.0
      Using MongoDB: 5.0.9
      Using Mongosh: 1.5.0> oid = new ObjectId("62c9a4673f0e25372db170ae")
      ObjectId("62c9a4673f0e25372db170ae")

      > typeof oid
      object

      > oid.str> typeof oid.str
      undefined> oid.toString()
      62c9a4673f0e25372db170ae> typeof oid.toString()
      string> oid.valueOf()
      ObjectId("62c9a4673f0e25372db170ae")> typeof oid.valueOf()
      object> oid === oid.valueOf()
      true

            Assignee:
            Unassigned Unassigned
            Reporter:
            lukasz@walukiewicz.eu Łukasz Walukiewicz
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: