json-server
json-server copied to clipboard
How to filter by an array that contains a value
Example:
GET HTTP://localhost/partners?segmentIds=1
I need segments 1 2 and 3, but it is only returning the segments with id 2 and 3
{
"segments": [
{
"id": 1,
"name": "Bear"
},
{
"id": 2,
"name": "Restaurant",
},
{
"id": 3,
"name": "Hamburgers",
}
],
"partners": [
{
"id": 1,
"name": "Bear Head",
"segmentIds": [1, 3]
},
{
"id": 2,
"name": "Cariboos",
"segmentIds": [1]
},
{
"id": 3,
"name": "Beer Beer",
"segmentIds": [1],
}
]
}
Would also like to know if this is possible
I just had to do this. You can use http://localhost:3000/partners?segmentIds_like=1
Key part is adding the _like
using like records that start with 1 are also returned. As for example:
"partners": [
{
"id": 121,
"name": "XXXXXX",
"segmentIds": [18]
}
]
is there any way to use filter with OR operator?
that's a good opportunity for PR.
I'll try to do it soon.
This feature would be really handy 👍
👍 Yes - very useful feature!
@ericmccarthy7 - your answer is helpful. Can you please assist how to configure the same in routes.json: https://stackoverflow.com/questions/52034326/mock-search-filter-using-json-server
@Nilegfx did , we find any resolution for the same . didn't find any thing in official document . Like keyword is giving other results as well.
Any update on this? It would be useful to be able to specify a _any or _all for searching within an array.