2

I would like to get only specific properties of multiple RedisJson objects stored in the DB.

For example, 2 RedisJson were created:

JSON.SET Cat:1 . '{"name":"Mitzi", "color":"pink", "age":1}'
JSON.SET Cat:2 . '{"name":"Lucky", "color":"black", "age":13}'

We are interested to get only properties "name" and "color" For a single object this would work:

JSON.GET Cat:1 .name .color

returns:

"{\".name\":\"Mitzi\",\".color\":\"pink\"}"

However, for multiple objects using MGET.

JSON.MGET Cat:1 Cat:2 .name .color

This obviously doesn't work, didn't figure out how to specify the properties as command arguments.

marina
  • 55
  • 4

1 Answers1

3
redis> JSON.MGET Cat:1 Cat:2 '$["name","color"]'
["Mitzi","pink"]
["Lucky","black"]
Lior Kogan
  • 19,919
  • 6
  • 53
  • 85
  • Another question on this, is there a method that will return also JSON properties names? As in case of missing properties we won't know which property the value belongs to. For example: JSON.MGET Cat:1 Cat:2 '$["name", "food", "color"]' will return the same result – marina Apr 19 '23 at 10:41
  • 1
    @marina not yet. Please follow https://github.com/RedisJSON/RedisJSON/issues/955 – Lior Kogan Apr 19 '23 at 10:43