We can scope queries in Mongoid using class methods, as follows:
Class Book
...
def self.premium
where(price: {'$gt': 20'})
end
End
Then we will use this query:
Book.premium
It will query for books with a price greater than 20.
We can scope queries in Mongoid using class methods, as follows:
Class Book
...
def self.premium
where(price: {'$gt': 20'})
end
End
Then we will use this query:
Book.premium
It will query for books with a price greater than 20.