ruby on rails - Mongoid Scope Check If Array Field Contains Value -
The solution to this question can be very easy, but I'm waving around with no answer.
I am using quietly in my Rail 4.1.4 app. I have a model in which an array Field which will house string values. I want a Mongoyeds to get examples in the scope of the model , where it is specific in the array field String value, which is given as a parameter for the scope. Suppose we have this model: How to write a very simple scope but a clue? ?? Regards !!! thank you in advanced. You are working a lot more if a field contains an array, you can search it As if it was not an array. For example, if you have a document: and you do a query like this: You will find that document. You do not need or are not anything complicated here; You can pretend that the array has a single value for simple questions like yours: You just need to join do not mind , Existing mangaodi docs are not quite clear on this stuff (or at least I can not get a clear explanation. )
class Monogel in some models :: documents are included in the moguid :: timestamp field: some_array, type: array, default: array.non scope: some_scope, - & gt; field does not work, because obviously, MongoDB Em> $ elemMatch needs to get criteria as value . But, how to say benchmark that the element should be equal to the given value. ???
{some_array: ['ou', 'is', 'pancakes', 'home?' ]}
where (: some_array => 'pancakes')
scope: some_scope, - & gt; (Value) {where (: some_array = & gt; value)}
$ elem match If you want to apply several conditions in the element, then
$ elemMatch document:
result: {$ elemMatch: {$ gte: 80, $ lt: 85}} // ^^^^^^^ array ^^^^^^^^ ^^^^^^^^^^^^^ many terms
Comments
Post a Comment