The solution for this question might look pretty simple, but I've been waving around with no answer.
I'm using Mongoid in my Rails 4.1.4 app. I have a model which contains an Array field that will house String values.
I need a Mongoid's scope in the model to retrieve those instances where this Array field contains a specific String value, given as a parameter to the scope. Let's say we have this model:
class SomeModel
include Mongoid::Document
include Mongoid::Timestamps
field :some_array, type: Array, default: Array.new
scope :some_scope, ->(value){ elem_match(some_array: value) }
end
The above scope doesn't work because, obviously, in MongoDB $elemMatch needs to receive a Criteria as the value. But, how would be the Criteria to just say that the element has to be equal to the given value???.
Any clues on how to write this pretty simple scope???.
Regards!!!. Thanks in advance.