Goalie
Goalie

Reputation: 3105

How do you search for all documents that have a specific embedded document in Mongoid?

Currently I use the following to search an individual document to see if a specific embedded document exists:

User.where(first_name:"Josh").first.attributes['address'].nil?

How do I search the entire User collection for documents that have the 'address' embedded document?

Thanks!

Upvotes: 0

Views: 57

Answers (1)

apneadiving
apneadiving

Reputation: 115511

Something like:

User.where(:address.exists => true)

Upvotes: 1

Related Questions