Skip to content

Instantly share code, notes, and snippets.

@jfinucane
Created February 24, 2016 19:30
Show Gist options
  • Save jfinucane/0e21fc39a13d51970cfb to your computer and use it in GitHub Desktop.
Save jfinucane/0e21fc39a13d51970cfb to your computer and use it in GitHub Desktop.
Dental plan results affected by Mongo query syntax
# Snippet illustrates a query on hbx_enrollemnts
# FINDS familes including ones that have ivl dental and employer_sponsored health
families = Family.where(:"households.hbx_enrollments.kind" => "employer_sponsored", :"households.hbx_enrollments.coverage_kind" => 'dental')
puts families.size #36
# FINDS families where the enrollment has coverage_kind='dental' and kind: 'employer_sponsored'
families=Family.where(:'households.hbx_enrollments' =>
{
"$elemMatch" => {
kind: 'employer_sponsored',
coverage_kind: 'dental'
}
})
puts families.size # 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment