0

I'm using node-redis library. I have redis key: test1 with value:

{
    "requests": [
        {
            "requestId": "123",
            "requestType": "TYPE_1",
            "foo": "bar",
            "timestampS": 1230011000
        },
        {
            "requestId": "124",
            "requestType": "TYPE_1",
            "foo": "bar2",
            "timestampS": 1230011050
        }
    ]
}

To get all requests with timestampS < 1230011040, I need to run:

const value = await this.client.json.get('test1', { path: `$.*[?(@.timestampS<1230011040)]` });

It works. The value is an array with one element (request object with "requestId": "123").

However, I don't know how to get an array with all request objects with timestampS < 1230011040 from redis key test2 with value:

{
  "123": {
        "requestId": "123",
        "requestType": "TYPE_1",
        "foo": "bar",
        "timestampS": 1230011000
    },
    "124": {
        "requestId": "124",
        "requestType": "TYPE_1",
        "foo": "bar2",
        "timestampS": 1230011050
    }
}

Is it possible?

2 Answers 2

0

In terms of JSON Path, yes, the filter selector operates on both stays and objects. For objects, it ignores the keys and iterates through the values.

I don't know whether redis supports that, but it's a pretty basic feature, so it should.

Also, when in doubt, just try it.

Sign up to request clarification or add additional context in comments.

2 Comments

gregsdennis thank you for your answer. Indeed, as I understand from the documentation: redis.io/docs/latest/develop/data-types/json/path, the path: $.*[?(@.timestampS<1230011040)] should work also for objects. However, I tried it and for some reason it doesn't work.
Then I think you're down to consulting any docs they have. At worst, raise an issue and get support.
0

It took me a some time, but the solution was easy. I just had to remove the unnecessary star (*) in the JSONPath. This path: $.[?(@.timestampS<1230011040)] works.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.