I have two models, a User and an embedded model Message
class User
include Mongoid::Document
embeds_many :messages
end
class Message
include Mongoid::Document
field :keywords, :type => Array
end
I am trying to do something like:
u = User.last
u.messages.where(:keywords => /sometext/).first
But this returns nothing, the regex seems to work fine if the field is not of type Array and is a String. How can I do something like this with Mongoid?
I should also mention this Mongo query works fine:
db.users.find({"messages.keywords" : /index/ })
mongoid. This is a wrapper around the MongoDB ruby driver and outputs its own queries as it sees fit. Do you have any way to check what querymongoidis actually running? Is it the same one that you ran?