Mongoid, scope if value is set?

I create a region in my rails application, I want my region to return documents that have anything specified for this field.

scope :address_available, where(:address => "")

Since some documents may not have this field, others will have a string as a value. But how can I return documents that are not nil?

+5
source share
1 answer

Use exists

scope :address_available, where(:address.exists => true)
+6
source

All Articles