I'm using mongodb and I've built to make the following query.
1 AccessToken.where('resource_owner_id').equals(event.resource_owner_id)
2 .where('revoked_at').equals(undefined)
3 .or([ { scopes: /resources/i }, { scopes: new RegExp(event.resource,'i') } ])
4 .or([ { device_ids: [] }, { device_ids: event.body.id } ])
For this example I'm using Mongoose and coffescript.
Unluckily it doesn't work as I want, mainly for the or statement. What I want is the two or on row 3 and 4 being independent.
This means that the field scopes (row 3) must contain the string resources or the string stored in event.resource, meanwhile the field device_ids must be empty or contain the id event.body.id.
From the tests I've prepared I can see that the or command put all together. This means that when just one of the four or conditions is satisfied I get the document.
- { scopes: /resources/i }
- { scopes: new RegExp(event.resource,'i') }
- { device_ids: [] }
- { device_ids: event.body.id }
What I'm not able to reach is to split them in two groups so that both the conditions related to the field scopes and the conditions related to the field device_ids can be satisfied.
Hope the problem is well described. Thanks.