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

ObjectId#toString and ObjectId#valueOf

    • Type: Icon: Question Question
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.2.0
    • Component/s: None
    • Labels:
      None

      2.2.0 changed the behavior of ObjectId#toString and ObjectId#valueOf. In 2.0.x
      ObjectId#toString would return an object ID string, like "50490f24a5b26b22e7000001", while in 2.2.0 it returns a string like "ObjectId(\"50490f24a5b26b22e7000001\")".

      This change breaks our MR jobs that use object IDs as object literal keys, e.g.

      var userEvent = {};
      userEvent[this.user_id] = 1;
      emit(key, userEvent);

      Through some experimentation we found that ObjectId#valueOf in 2.2.0 returns a representation that we need, i.e. "50490f24a5b26b22e7000001". However, we also found that the behavior of ObjectId#valueOf was different in 2.0.x, where it return the object itself.

      We couldn't find any documentation on ObjectId#valueOf and we're concerned that its behavior could change in future releases again. Can we rely on #valueOf remaining the same in the future? Or is there a more reliable way to convert ObjectId to a string, given that the 2.2.0 ObjectId#toString result is unusable for our purposes?

            Assignee:
            milkie@mongodb.com Eric Milkie
            Reporter:
            alexeits Alex Tsibulya
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: