0

in mongo:

{
   "_id": ObjectId("519733333fb6664b5d000000"),
   "email": "[email protected]",
   "dates": {
       "pre_register": "2013-05-18 04:53:38" 
   } 
}

my model:

class Member
      include Mongoid::Document
      store_in collection:'member'

      field :email
      field :dates
end

how to use the field dates.pre_register? I tried this:

field :dates.pre_register

but no success.

1 Answer 1

1

Your problem is that field actually defines string types by default.

I think you should think the other way around. Let mongoid generate the mongodb document for you. One way to achieve what you are looking for is to define another Mongoid::Document "Date" and have your class Member embed id as:

embedds_many :dates

This would work. If you don't want to define a custom Mongoid::Document for that, just use a hash field like:

field :dates, :type => Hash
Sign up to request clarification or add additional context in comments.

1 Comment

thanks! I'm trying to use this with rails_admin but seems this gem has no support for editing hash/array field

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.