Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-3167

Model.find with invalid ID gives DocumentNotFound instead of InvalidObjectId

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 5.0.0
    • Component/s: None
    • Labels:

      Description

      Calling Model.find with an invalidly formatted BSON::ObjectID used to throw a BSON::InvalidObjectId error in Mongoid 2.x

      However, in Mongoid 3, it seems it throws a Mongoid::DocumentNotFound error instead of a Moped::BSON::InvalidObjectId error as expected. Is there some sort of option to have it throw the InvalidObjectId error again?

      id = Moped::BSON::ObjectId.new
       => "51e476877a93d0e9ac00000d"
      Player.find(id)
      Mongoid::Errors::DocumentNotFound:
       
      Player.find('abc')
      Mongoid::Errors::DocumentNotFound:
      

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: