alikewmk
alikewmk

Reputation: 145

How to use nested and or query in Mongoid 3

In former version of Mongoid I would write:

Clothes.where("$or" => [{"$and" => [{_type: "Shoes"}, {is_secondhand: false}]}, 
                        {"$and"=> [{_type: "Shirts"}, {is_secondhand: true}]}])

How should I write that in Mongoid 3.0.13?

Upvotes: 0

Views: 412

Answers (1)

Tsagadai
Tsagadai

Reputation: 887

You probably don't need those ands.

Try this:

Clothes.or({_type: "Shoes", is_secondhand: false},
           {_type: "Shirts", is_secondhand: true})

A lot has changed in Mongoid 3 and most of the querying selectors were moved to Origin. Have a look at the Origin documentation.

Upvotes: 1

Related Questions