title: Save a pdf in mongodb with mongoid without GridFS
body: <p>I want to save a small pdf file in a mongodb database. I use Ruby (2.0.0), Padrino (0.12.5) and MongoId (3.0.0), MongoDB(2.6). Since my filesize is around 1MB, I will not need the complexity of GridFS.</p>
  
  <p>I am new to MongoDB and expected that small files can be easily saved without worrying about paths and the filesystem.</p>
  
  <pre><code>class Client
    include Mongoid::Document
    include Mongoid::Timestamps # adds created_at and updated_at fields
  
    field :last_name, :type =&gt; String
    field :cv_pdf, :type =&gt; Moped::BSON::Binary
   end
  </code></pre>
  
  <p>If I use a test file in the console I get an error when I want to save the pdf file to the DB:</p>
  
  <pre><code>2.0.0-p353 :015 &gt;   c = Client.first
      =&gt; #&lt;Client _id: 55883b5168874459df000001, _type: nil, created_at: 2015-06-22 16:44:01 UTC,
      updated_at: 2015-06-23 06:45:57 UTC, last_name: "Foo", cv_pdf: ""&gt; 
  2.0.0-p353 :016 &gt; f = File.open("test1.pdf")
      =&gt; #&lt;File:test1.pdf&gt; 
  2.0.0-p353 :017 &gt; c.cv_pdf = f
      =&gt; #&lt;File:test1.pdf&gt; 
  2.0.0-p353 :019 &gt; c.save
    NoMethodError: undefined method `__bson_dump__' for #&lt;File:test1.pdf&gt; 
    [...]
  </code></pre>