or method
Combine current expression with expression in parameter by logical operator OR. See MongoDB doc For example inventory.find(where.eq('price', 1.99).and(where.lt('qty',20).or(where.eq('sale', true))));
This query will select all documents in the inventory collection where:
- the price field value equals 1.99 and
- either the qty field value is less than 20 or the sale field value is true
MongoDB json query from this expression would be
{'$query': {'$and': [{'price':1.99}, {'$or':
{'qty': {'\$lt': 20 }}, {'sale': true }
}]}}
Implementation
SelectorBuilder or(SelectorBuilder other) {
if (_query.isEmpty) {
throw StateError('`And` operation is not supported on empty query');
}
if (_query.containsKey('\$or')) {
var expressions = _query['\$or'] as List;
expressions.add(other._query);
} else {
var expressions = [_query];
expressions.add(other._query);
map['\$query'] = {'\$or': expressions};
}
return this;
}