Hi all,
I have the following documents:
class User
include Mongoid::Document
embeds_many :profiles
end
class Profile
include Mongoid::Document
field :data, :type => Array, :default => []
embedded_in :user, :inverse_of => :profiles
end
I'm trying to query the array field "data" inside the Profile document
but it does not work. I always get zero hits.
Here is the code:
user_profile = UserProfile.new
user_profile.data = [{"action" => "del", "approve" => "always"},
{"action" => "add", "approve" => "never"}]
user = User.new
user.name = "hugo"
user.profiles << user_profile
user.save
user = User.find(:first, :conditions => {"name" => "hugo"})
user.profiles.where("data" => { "$in" => { "$elemMatch" => { "action"
=> "add" }} }).size()
Can anyone help me?
Thanks.
Best regards,
Hugo