Querying items

This method will query items based on URL parameters appended to the request. This method uses the S3 Select API, allowing for SQL-like queries on your data within NotoDB sets.

Querying items

Example syntax for the query endpoint.

POST
/{bucket name}/sets/{set name}/query?{key}={optional operator}:{value}

A query for a first name of `Velma` on a set that contains a list of users might look something like following:

POST
/mybucket/sets/users/query?first_name=Velma
RESPONSE BODY
[
  {
    "id": 20,
    "first_name": "Velma",
    "last_name": "Omand",
    "email": "vomandj@creativecommons.org",
    "ip_address": "188.130.239.149",
    "job_title": "Administrative Assistant III",
    "_id": "obhxfii36ldhscoc",
    "_createdAt": 1652325906197,
    "_updatedAt": 1652325906197
  }
]

The above example uses exact matching on the `first_name` field. However, we can also use operators to compare field values with our query parameter. Here's an example where we are looking for anyone with a first name that contains `ma` in it:

POST
/mybucket/sets/users/query?first_name=like:ma
RESPONSE BODY
[
  {
    "id": 80,
    "first_name": "Salvador",
    "last_name": "Zanardii",
    "email": "szanardii27@go.com",
    "ip_address": "123.140.133.176",
    "job_title": "Analyst 3 Programmer",
    "_id": "zu9qj80xilt62myr",
    "_createdAt": 1652325906198,
    "_updatedAt": 1652569393790
  },
  {
    "id": 81,
    "first_name": "Ina",
    "last_name": "Lethardy",
    "email": "ilethardy28@weather.com",
    "ip_address": "188.169.111.212",
    "job_title": "Graphic Designer",
    "_id": "csl1azypsz2wxr99",
    "_createdAt": 1652325906198,
    "_updatedAt": 1652325906198
  },
  {
    "id": 82,
    "first_name": "Mathe",
    "last_name": "Brazer",
    "email": "mbrazer29@tumblr.com",
    "ip_address": "117.153.194.188",
    "job_title": "Research Nurse",
    "_id": "6p9xk8rhm478vfp8",
    "_createdAt": 1652325906198,
    "_updatedAt": 1652325906198
  }
]

Query operators

Operator
Equalsfirst_name=bob
Likefirst_name=like:bob
Starts withfirst_name=start:bob
Ends withfirst_name=end:bob
Greater thanage=gt:30
Greater than or equal toage=gte:30
Less thanage=lt:30
Less than or equal toage=lte:30

Multiple query operators

You can chain together multiple query operators in a single request. Example:

POST
/mybucket/sets/users/query?age=gt:30&job_title=like:engineer
RESPONSE BODY
[
  {
    "id": 20,
    "first_name": "Jennifer",
    "last_name": "Omand",
    "email": "jomand@adobe.com",
    "age": 32,
    "job_title": "Software Engineer",
    "_id": "obhxfii36grhscoc",
    "_createdAt": 1652325906197,
    "_updatedAt": 1652325906197
  }
]

Converting types for comparison

NotoDB will not imply the type of values provided. A string is always a string and an integer (int) is always an integer. An item with type int age of 30 is not equivalent to item with type string age of "30". With NotoDB, you can convert an int to a string by enclosing your URL parameter value with double quotes. Example:

POST
/mybucket/sets/users/query?age="32"
RESPONSE BODY
[
  {
    "id": 20,
    "first_name": "Jennifer",
    "last_name": "Omand",
    "email": "jomand@adobe.com",
    "age": "32",
    "job_title": "Software Engineer",
    "_id": "obhxfii36grhscoc",
    "_createdAt": 1652325906197,
    "_updatedAt": 1652325906197
  }
]

While you can convert an int to a string, you can not currently convert a string to an int in your query.

Next articleAggregate functions