select¶
select keeps only the columns you name. With -, it keeps everything but the columns you name. The answer is smaller, and holds only what your screen needs.
In short
?select=first_name,last_name: only these columns.?select=-password: all but this one.- With a schema, the primary key always comes along.
- Columns the groups of the caller may not read never come back.
Answer : the primary key always comes along
{
"success": true,
"statusCode": 200,
"data": [
{ "customer_id": 1, "first_name": "Bob", "last_name": "Lin" },
{ "customer_id": 2, "first_name": "Alice", "last_name": "Page" }
]
}
Everything but these fields
GET /api/schema/admin/mysql8/inventory/customers?select=-last_update,-isActive
Body of the query APIs : a string or an object
{ "find": {}, "select": "first_name,last_name" }
{ "find": {}, "select": { "first_name": 1, "last_name": 1 } }
- On MongoDB, a nested field works too :
select=address.city. - Do not mix kept and left-out columns. If you do, only the left-out ones count :
select=first_name,-pincodereturns every column butpincode. - On a schema API, a column the schema does not have stops the call :
Unable to find [nick_name] columns in schema of [mysql8 → inventory → customers]. - The write APIs (save, master save, update by id, replace by id, remove by id) take
selecttoo. It shapes the row they answer. - In a
deepitem,selectpicks the columns of the related rows :deep=[{s_key:'customer_id',t_col:'orders',t_key:'customer_id',select:'order_no,total'}]. - A column the groups of the caller may not read never comes back, selected or not. See the column permissions of API group permission.
Arrays on MongoDB : $slice and $elemMatch¶
A field of a MongoDB document can hold an array. select takes the two operators MongoDB has to shape one, on the generated and on the schema APIs :
| Operator | Example | The array comes back with |
|---|---|---|
$slice |
{ "tags": { "$slice": 2 } } |
its first 2 items, its last 2 with -2 |
$slice |
{ "orders": { "$slice": [ 10, 5 ] } } |
5 items after the first 10 : [ skip, limit ] |
$elemMatch |
{ "orders": { "$elemMatch": { "status": "PAID" } } } |
its first item which meets the conditions |
The last 3 orders of each customer
{ "find": {}, "select": { "first_name": 1, "orders": { "$slice": -3 } } }
As a query param (JSON5)
GET /api/schema/admin/mongodb/inventory/customers?select={first_name:1,orders:{$slice:-3}}
- Next to fields with
1, those fields and the array come back. Alone,$sliceleaves every other field in, and$elemMatchreturns the array with the id only, as MongoDB does. - The conditions of
$elemMatchare the ones of find. The schema APIs convert their values to the types of the schema :{ "order_id": "5" }matches the number 5, an id string an ObjectId. $elemMatchis for an array at the top of the document.$slicecuts a nested one too :{ "orders.items": { "$slice": 1 } }.- On the schema APIs
$slicetakes numbers only, and any other object inselectselects the whole field : nothing is computed from other fields. selectof adeepitem and of the write APIs takes them too.- A table of a SQL instance holds no arrays : there the field is selected as it is.