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

Cannot compare different instances of ObjectIds with same value

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: JavaScript
    • Labels:
      None
    • Environment:
      shell
    • Fully Compatible
    • ALL

      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

            Assignee:
            backlog-server-platform DO NOT USE - Backlog - Platform Team
            Reporter:
            octave Yuriy Bogdanov
            Votes:
            4 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated:
              Resolved: