I have a set of records like the following:
[
{ title: 'foo', members: [ 'a', 'b' ] },
{ title: 'bar', members: [] },
{ title: 'fiz', members: [ 'b' ] }
]
The members prop is used for restricting certain records so what I'm hoping to do is check the property and if empty or doesn't exist OR it contains the member return the item.
For example:
- User
awould get backfoo(is a member) andbar(no member restrictions) - User
bwould get all three because they are a member on0and2and no member restrictions are set on on1
var user = 'a'; db.collection.distinct('title', { '$or': [ { 'members': user }, { 'members.0': { '$exists': false } } ] });