this document structure
{ someprop: 'string value', options:{ environment: [{value: 'gym'}, {value:'water'}, {value: 'home', label:'other string'}] } }
i need filter documents options.environment
contains {value: 'gym'}
, {value: 'water'}
.
what best way make query using mongodb aggregate $match
or strategy ($unwind
/$group
, $map
)?
you can use $all
query operator this:
{ "options.environment.value": { "$all": ["gym", "water"] } }
generally speaking, mongodb flattens structure before running query. in case, means searching document shaped this:
{ "someprop": "string value", "options": { "environment": { "value": ["gym", "water", "home"], "label": ["other string"] } } }
if want opposite behavior, can use $elemmatch
query operator.
none of specific aggregation framework, can use regular find operation if don't need other aggregation framework features.