mongoid/mongoid — Issue #1793: field-values should be of the defined field-type
Author: banditj
Created: 2012-03-06 18:51:57+00:00
State: open

it would be nice to be able to add a strict_field_types=true to the configuration of mongoid

```ruby

# the model
class User
include Mongoid::Document
include Tire::Model::Search
include Tire::Model::Callbacks

field :snumber, :type => Integer
field :age, :type => Integer
field :income, :type => Float

field :lname, :type => String
field :fname, :type => String
field :username, :type => String

field :birthday, :type=>Date

# the problem
a = User.new
a.age = "asdf"
a.save
=>true

```
as other gems seem to rely on correct field-values (should be an integer)
this leads to problems

sample: tire and elasticsearch
here tire sends age as a wrong string-value to elasticsearch although elasticsearch expects an integer .
this leads to an exception in elasticsearch, tire logs a "bad request" and the user won't get indexed.

I made a demo-mongoid-tire app which also illustrates this problem

https://github.com/banditj/demo_mongoid_tire

current workaround is to validate_numericality of all floats and integer fields