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

Change _massageObject string processing

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.3.11
    • Affects Version/s: None
    • Component/s: Shell
    • Labels:
      None
    • Fully Compatible
    • Build B (10/30/15), Build C (11/20/15), Platforms 2016-08-26

      _massageObject (used by db.foo.find() and db.foo.remove()) converts a 24 char string into { _id: "..." }. Surely the intention behind the length == 24 check is to convert the string into the corresponding ObjectId()?

      src/mongo/shell/collection.js:134-158

      Unable to find source-code formatter for language: diff. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
       DBCollection.prototype._massageObject = function( q ){
           if ( ! q )
               return {};
       
           var type = typeof q;
       
           if ( type == "function" )
               return { $where : q };
       
           if ( q.isObjectId )
               return { _id : q };
       
           if ( type == "object" )
               return q;
       
           if ( type == "string" ){
               if ( q.length == 24 )
      -            return { _id : q };
      +            return { _id : ObjectId( q ) };
       
               return { $where : q };
           }
       
           throw Error( "don't know how to massage : " + type );
       
       }
      

            Assignee:
            matt.cotter Matt Cotter
            Reporter:
            kevin.pulo@mongodb.com Kevin Pulo
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: