The date field when save to mongodb is in the format of:
{ “_id” : ObjectId(“4f03283e1d4ee82215000002”), “name” : “nano3”,
“category_id” : ObjectId(“4f022b411d4ee8105700001c”), “price” : 20,
“production_date(3i)” : “1”, “production_date(2i)” : “1”,
“production_date(1i)” : “2011”, “description” : “a music player with
video play function” }
when I try to get the date using @product.production_date from my model it failed. I am using Mongoid mapper
It fails because you don’t have any fields named “production_date”.
What you do have is fields named “production_date(3i)”, “production_date(2i)”, and “production_date(1i)”.
You should be saving instances of the time class which can be properly serialized by the ruby driver.
Time.noworTime.utc(2011,1,1)will probably do what you want.