Why doesn't this work:
ruby-1.8.7-p249 > List.create :search_terms => 'foo'
=> #<List _id: 4c9044a02249c7a5e2000001, search_terms: "foo", user_id: nil>
ruby-1.8.7-p249 > List.all
=> #<Mongoid::Criteria:0x1030dea90 @klass=List, @documents=[], @selector={}, @options={}>
ruby-1.8.7-p249 > List.all.documents
=> []
To search the array of object in MongoDB, you can use $elemMatch operator. This operator allows us to search for more than one component from an array object.
Filter MongoDB Array Element Using $Filter Operator This operator uses three variables: input – This represents the array that we want to extract. cond – This represents the set of conditions that must be met. as – This optional field contains a name for the variable that represent each element of the input array.
The easiest way is to just filter the shapes in the client. If you really need the correct output directly from MongoDB, you can use a map-reduce to filter the shapes. Save this answer.
In your case you could try: Person. find({ members: { $elemMatch: { id: id1 } } });
I think what you're looking for is:
List.all.to_a
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With