JP Silvashy
JP Silvashy

Reputation: 48535

Mongoid, scope if a value is set?

I'm creating a scope in my rails app, I want my scope to return documents which have anything set for the field in question.

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

So because some documents might not have that field defined, and others will have a string as the value. But how can I return the documents which are not nil?

Upvotes: 5

Views: 1237

Answers (1)

Kyle
Kyle

Reputation: 22268

Use exists

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

Upvotes: 6

Related Questions