Currently, I have problem when using Rest API in DataStax Astra.
For example data:
{
"count": 2,
"Members": [
{
"created_at": "",
"intfield": null,
"id": "294",
"role": "BA",
"username": "Join"
},
{
"created_at": "",
"intfield": null,
"id": "180",
"role": "Back",
"username": "Kien Nguyen"
},
{
"created_at": "",
"intfield": null,
"id": "180",
"role": "Back",
"username": "Kien Nguyen"
}]
}
Now, I want to get all Member with role Back (backend). I try using 2 api same the above image API But not success. Maybe, I passed incorrect input or input body to 2 api. I searched the forums but couldn't find a solution.
Any answer is appreciated.
Thank a lot!
Your question is missing crucial details including:
In any case, the result set you posted appears to have been "doctored" because it reports
"count": 2
but there are 3 records in the list, with"id": "180"
duplicated.So instead, I'm going to use an example to illustrate how to filter on a field. Here is the table I've created in my DB:
It is populated with the following sample data:
To filter based on
id = 123
, we will use the following:/api/rest/v2/keyspaces/community/members
where={"id": {"$eq":123}}
The resulting request URL for REST API call (with URL-escaped characters) is:
and the response is:
If I try to filter with
role = 'backend'
(orwhere={"role": {"$eq":"backend"}}
), this REST API call:will return an error
400
becauserole
is not the partition key so we can't filter on it:The workaround is to index the
role
column so we can filter on it:Now we can query it with this REST API call:
to get:
For details and a few more examples, see Developing with the Astra DB REST API. Cheers!