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

Custom ids of integer not found from params

      When using a custom id of integer type Mongoid throws an error when finding a document by the string id from the controller parameter.

      This code illustrates the problem:

      class Band
        include Mongoid::Document
        field :band_id, :type => Integer,    :type => Integer, default: ->{ Random.rand(10000000000).to_i }
        field :_id, :type => Integer, default: ->{ band_id }
      end
      

      Mongoid throws an error if the id is provided as a string from a controller parameter:

      1.9.3p194 :007 >   Band.create
       => #<Band _id: 8219652764, _type: nil, band_id: 8219652764> 
      
      1.9.3p194 :008 > Band.find("8219652764")
      Mongoid::Errors::DocumentNotFound: 
      Problem:
        Document(s) not found for class Band with id(s) 8219652764.
      
      

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

              Created:
              Updated:
              Resolved: