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

Model.find with invalid ID gives DocumentNotFound instead of InvalidObjectId

    • Type: Icon: Task Task
    • Resolution: Done
    • 5.0.0
    • Affects Version/s: None
    • Component/s: None

      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:
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            hahuang65 hahuang65
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: