Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to search for records having or not having a property? #344

Closed
Natim opened this issue Dec 16, 2015 · 8 comments
Closed

How to search for records having or not having a property? #344

Natim opened this issue Dec 16, 2015 · 8 comments

Comments

@Natim
Copy link
Member

Natim commented Dec 16, 2015

Let say I have some records.

How can I select only records having a text attribute?

https://kinto-ota.dev.mozaws.net/v1/buckets/mozlando/collections/wall/records?having_text=true ?
https://kinto-ota.dev.mozaws.net/v1/buckets/mozlando/collections/wall/records?having_text=false ?

@almet
Copy link
Member

almet commented Dec 16, 2015

contains?

@Natim
Copy link
Member Author

Natim commented Dec 16, 2015

Contains would probably already be used by #343

@almet
Copy link
Member

almet commented Dec 16, 2015

defined, exists?

@Natim
Copy link
Member Author

Natim commented Dec 22, 2015

I like defined 👍

  • text_defined=true
  • text_defined=false

@leplatrem
Copy link
Contributor

  • ?has_attr=true
  • ?has_attr=false

@gabisurita
Copy link
Member

gabisurita commented Oct 10, 2016

It's a bit unfriendly, but this is possible via:

  • ?attr for records not having the attribute
  • ?not_attr for records having the attribute defined

But I can work on this if changes are needed.

An example:

$ http GET localhost:8888/v1/buckets/default/collections/c1/records --auth aaa:aaa
HTTP/1.1 200 OK
Access-Control-Expose-Headers: Content-Length, Expires, Alert, Retry-After, Last-Modified, Total-Records, ETag, Pragma, Cache-Control, Backoff, Next-Page
Cache-Control: no-cache, no-store
Content-Length: 166
Content-Type: application/json; charset=UTF-8
Date: Mon, 10 Oct 2016 22:20:16 GMT
Etag: "1476137810045"
Last-Modified: Mon, 10 Oct 2016 22:16:50 GMT
Server: waitress
Total-Records: 3

{
    "data": [
        {
            "id": "r3",
            "last_modified": 1476137810045,
            "param": "nope"
        },
        {
            "id": "r2",
            "last_modified": 1476137797249
        },
        {
            "id": "r1",
            "last_modified": 1476137764176,
            "param": "yeap"
        }
    ]
}

$ http GET localhost:8888/v1/buckets/default/collections/c1/records?not_param --auth aaa:aaa
HTTP/1.1 200 OK
Access-Control-Expose-Headers: Content-Length, Expires, Alert, Retry-After, Last-Modified, Total-Records, ETag, Pragma, Cache-Control, Backoff, Next-Page
Cache-Control: no-cache, no-store
Content-Length: 124
Content-Type: application/json; charset=UTF-8
Date: Mon, 10 Oct 2016 22:20:21 GMT
Etag: "1476137810045"
Last-Modified: Mon, 10 Oct 2016 22:16:50 GMT
Server: waitress
Total-Records: 2

{
    "data": [
        {
            "id": "r3",
            "last_modified": 1476137810045,
            "param": "nope"
        },
        {
            "id": "r1",
            "last_modified": 1476137764176,
            "param": "yeap"
        }
    ]
}

$ http GET localhost:8888/v1/buckets/default/collections/c1/records?param --auth aaa:aaa
HTTP/1.1 200 OK
Access-Control-Expose-Headers: Content-Length, Expires, Alert, Retry-After, Last-Modified, Total-Records, ETag, Pragma, Cache-Control, Backoff, Next-Page
Cache-Control: no-cache, no-store
Content-Length: 52
Content-Type: application/json; charset=UTF-8
Date: Mon, 10 Oct 2016 22:20:25 GMT
Etag: "1476137810045"
Last-Modified: Mon, 10 Oct 2016 22:16:50 GMT
Server: waitress
Total-Records: 1

{
    "data": [
        {
            "id": "r2",
            "last_modified": 1476137797249
        }
    ]
}

@glasserc
Copy link
Contributor

glasserc commented Jun 7, 2017

This only happens to work due to a quirk of how we handle missing fields as the empty string. I'm going to add a has filter, per @leplatrem.

@glasserc
Copy link
Contributor

glasserc commented Jun 8, 2017

Added a has_ filter in #1258.

@glasserc glasserc closed this as completed Jun 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants