C# RedisJson 'OR' not working as expected

111 views Asked by At

I'm having a problem with RedisJson when trying to filter a JSON. Hope you can help me. When I use he OR statement in the JsonPath parameter doesn't filter as expected. If some condition not exist just return an empty array.

I have an event ids list, possible values are:

EventType = 1
EventType = 2
EventType = 3
EventType = 4
EventType = 5
{ "Events": [ { "EventId": 1}, { "EventId": 3} ] }

If I filter this way:

var data = await _cache.Database.JsonGetAsync(key, "$.Events[?( @.EventId == 1 || @.EventId == 3 )]");

Returns both values, with no problem. But if I do this:

var data = await _cache.Database.JsonGetAsync(key, "$.Events[?( @.EventId == 1 || @.EventId == 2 )]");

Returns an empty array, it looks like if one of the values not exists(in this case 2) then returns nothing instead of only the ones available(event id 1 in this case). The OR option doesn't work as expected.

I tried using the default one(StackExchange.Redis) with the same results:

var data = await _cache.Database.ExecuteAsync("JSON.GET", key, "$.Events[?( @.EventId == 1  ||  @.EventId == 2 )]");

Do you guys knows what is the reason? is there a solution or a workaround for this problem?

I'm new with redis and probably I'm doing something wrong.

0

There are 0 answers