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

Cannot compare different instances of ObjectIds with same value

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: JavaScript
    • Labels:
      None
    • Environment:
      shell
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL

      Description

      Simple test:

      > a = ObjectId() 
      ObjectId("4d6e43c970953cc4bf43b8cc") 
      > db.test.insert({a:a}) 
      > doc = db.test.findOne() 
      { 
              "_id" : ObjectId("4d6e43d170953cc4bf43b8cd"), 
              "a" : ObjectId("4d6e43c970953cc4bf43b8cc") 
      } 
      > doc.a.equals(a) 
      true 
      > doc.a.toString() === a.toString() 
      true 
      > doc.a === a 
      false
      > doc.a == a     
      false
      > db.version() 
      1.7.4 
      

      For example, PHP driver works great with it:

      <?php
      $id = new MongoID();
      $sameId = new MongoID((string)$id);
       
      var_dump($id == $sameId); // bool(true)
      var_dump($id === $sameId); // bool(false)
      

      Followed by discussion in groups:
      http://groups.google.com/group/mongodb-user/browse_thread/thread/77c0c55e24e97a08

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                4 Vote for this issue
                Watchers:
                14 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: