Auto generated schema based AGGREGATE API
[Mongo Database Only]
Table structure
customer_id | first_name | last_name | last_update | pincode | isActive |
---|---|---|---|---|---|
1 | Bob | lin | 2022-11-14 04: 34: 58 | 382345 | 1 |
2 | Alice | Page | 2022-10-15 02: 10: 40 | 382346 | 1 |
3 | Mallory | Brown | 2022-09-13 03: 44: 05 | 382347 | 1 |
4 | Eve | Mathly | 2022-11-12 01: 59: 33 | 382348 | 1 |
5 | Eve | Page | 2022-11-12 01: 59: 33 | 382349 | 1 |
Request Method: POST
Basic Aggregation
URL
Request Payload[
{
"$group": {
"_id": "$_id",
"total": {
"$sum": "$customer_id"
}
}
},
{
"$match": {
"total": {
"$gt": 1
}
}
},
{
"$sort": {
"total": -1
}
},
{
"$count": "CountValue"
}
]
$project stage
- It will return documents/rows where the first_name field is a small case.
URL
Request Payload$addFields
- It will return documents/rows with a new virtual column "full_name" with concat first_name and last_name field data.
URL
Request Payload$bucket
- It will return documents/rows where we can group products with a specific price range with a total number of product counts in that range.
URL
Request Payload[
{
"$bucket": {
"groupBy": "$price",
"boundaries": [
10000,
20000,
30000,
40000,
50000
],
"default": "Other",
"output": {
"count": {
"$sum": 1
},
"product_details": {
"$push": {
"name": "$name",
"price": "$price"
}
}
}
}
}
]
$facet with multiple $bucket
-
It will return documents/rows where,
- we can group products with a specific price range with a total number of product counts in that price.
- we can group products with a specific category range with a total number of product counts in that category.
URL
Request Payload[
{
"$facet": {
"price": [
{
"$bucket": {
"groupBy": "$price",
"boundaries": [
10000,
20000,
30000,
40000,
50000,
60000,
70000,
80000
],
"default": "Other",
"output": {
"count": {
"$sum": 1
},
"product_details": {
"$push": {
"name": "$name",
"price": "$price"
}
}
}
}
}
],
"categories": [
{
"$bucket": {
"groupBy": "$category_id",
"boundaries": [
10000,
20000,
30000,
40000,
50000,
60000,
70000,
80000
],
"default": "Other",
"output": {
"count": {
"$sum": 1
},
"product_details": {
"$push": {
"name": "$name",
"id": "$id",
"category_id": "$category_id"
}
}
}
}
}
]
}
}
]
$collStats, latencyStats > histograms, storageStats, count
URL
Request Payload$count
- It will return documents/rows count where the price is greater than "10000"
URL
Request Payload$limit
- It will return only the first two documents/rows.
URL
Request Payload$lookup
- It will return documents/rows of products nested with customer data.
URL
Request Payload[
{
"$lookup": {
"from": "products",
"localField": "customer_id",
"foreignField": "owner_id",
"as": "customer_data"
}
}
]
$match
- It will return documents/rows where first_name match with "Bob"
URL
Request Payload$redact, $cond, if, then, else, $$DESCEND, $$PRUNE
URL
Request Payload[
{
"$redact": {
"$cond": {
"if": {
"$eq": [
"$first_name",
"JOHNNY"
]
},
"then": "$$DESCEND",
"else": "$$PRUNE"
}
}
}
]
$replaceRoot, newRoot
- It will return a new virtual column with the name "full_name" with the concatenation of two columns first_name and last_name
URL
Request Payload[
{
"$replaceRoot": {
"newRoot": {
"full_name": {
"$concat": [
"$first_name",
" ",
"$last_name"
]
}
}
}
}
]
$sample
- It will return the first two samples of documents/rows.
URL
Request Payload$skip
- It will skip the first two records and return documents/rows.
URL
Request Payload$sort
- Sorting value -1 gives a response in descending order and 1 in ascending order.
- The below payload will sort data in ascending order.
URL
Request Payload- It will sort data in descending order.
URL
Request Payload$unwind, $sortByCount
- It will first unwind the data from JSON to node ages and then sort the data.
URL
Request Payload$abs, $subtract
URL - It will subtract tax amount from total amount and return value in "Grand_Total"
URL
Request Payload$add
- It will add tax amount into total amount and return value in "Grand_Total"
URL
Request Payload$ceil, $floor
- ceil: If the value is decimal then round the price, adding with +1
- floor: If the value is decimal then round the price, remove the decimal
URL
Request Payload[
{
"$project": {
"ceilingValue": {
"$ceil": "$price"
},
"floorValue": {
"$floor": "$price"
},
"id": 1
}
}
]
$divide
- It will return a value divided by 100.
URL
Request Payload$multiply
- It will return "Grand_Total" after multiplying the price by quantity.
URL
Request Payload$arrayElemAt
- It will return the color of index 1 of attributes.color array.
URL
Request Payload$filter
- It will filter data with age greater than 50
URL
Request Payload[
{
"$project": {
"ages": {
"$filter": {
"input": "$ages",
"as": "age",
"cond": {
"$gte": [
"$$age.age",
50
]
}
}
}
}
}
]
$in
- It will return documents/rows where hobbies equal to "traveling"
URL
Request Payload[
{
"$project": {
"customer_id": "$customer_id",
"TravelingHobby": {
"$in": [
"traveling",
"$hobbies"
]
}
}
}
]
$indexOfArray
- It will return the index of "ages.birth_year = 1971" from the array.
URL
Request Payload[
{
"$project": {
"customer_id": "$customer_id",
"index": {
"$indexOfArray": [
"$ages.birth_year",
1971
]
}
}
}
]
$isArray
- It will return documents/rows which fulfill the condition.
URL
Request Payload[
{
"$project": {
"isHobbyCricket": {
"$cond": {
"if": {
"$isArray": "$hobbies"
},
"then": {
"$in": [
"traveling",
"$hobbies"
]
},
"else": "One or more fields is not an array."
}
}
}
}
]
$map
- It will return documents/rows with only integer value from distance field value, and truncate the decimal value from distance.
URL
Request Payload[
{
"$project": {
"integerValues": {
"$map": {
"input": "$distances",
"as": "decimalValue",
"in": {
"$trunc": "$$decimalValue"
}
}
}
}
}
]
$reverseArray
- It will return the reverse value of the array.
URL
Request Payload$size
- It will return the size of the array as per the condition.
URL
Request Payload[
{
"$project": {
"customer_id": 1,
"address": 1,
"numberOfHobbies": {
"$cond": {
"if": {
"$isArray": "$hobbies"
},
"then": {
"$size": "$hobbies"
},
"else": "NA"
}
}
}
}
]
$and
- It will return documents/rows, and the result equals true where the price is greater than 60000 and category_id less than 45000.
URL
Request Payload[
{
"$project": {
"id": "$id",
"result": {
"$and": [
{
"$gt": [
"$price",
60000
]
},
{
"$lt": [
"$category_id",
45000
]
}
]
}
}
}
]
$not
- It will return documents/rows, the result equals false where the price is greater than 30000.
URL
Request Payload$or
- It will return documents/rows, and the result equals true where the price is greater than 60000 or category_id less than 1000.
URL
Request Payload[
{
"$project": {
"id": "$id",
"result": {
"$or": [
{
"$gt": [
"$price",
60000
]
},
{
"$lt": [
"$category_id",
1000
]
}
]
}
}
}
]
$cmp
- It will return documents/rows, "comparePrice equals to 1" where price greater than 42187 else "comparePrice equals to -1"
URL
Request Payload$eq
- It will return documents/rows, "equalPrice equals to true" where price equals 42187 else "equalPrice equals to false"
URL
Request Payload$gt
- It will return documents/rows, "graterPrice equals to true" where price grater then 42187 else "graterPrice equals to false"
URL
Request Payload$gte
- It will return documents/rows, "gePrice equals to true" where price grater then or equals to 42187 else "gePrice equals to false"
URL
Request Payload$lt
- It will return documents/rows, "lessPrice equals to true" where price less then 42187 else "lessPrice equals to false"
URL
Request Payload$lte
- It will return documents/rows, "ltePrice equals to true" where price less than equals to 42187 else "ltePrice equals to false"
URL
Request Payload$ne
- It will return documents/rows, "nePrice equals to true" where price not equals to 42187 else "nePrice equals to false"
URL
Request Payload$cond
- It will return documents/rows, where price grater than 50000 discount apply 30% else 10%
URL
Request Payload[
{
"$project": {
"id": 1,
"price": 1,
"discount": {
"$cond": {
"if": {
"$gt": [
"$price",
50000
]
},
"then": 30,
"else": 10
}
},
"_id": 0
}
}
]
$ifNull
- It will return documents/rows, if shipping object is available then return in response else return null
URL
Request Payload[
{
"$project": {
"id": 1,
"price": 1,
"shipping": {
"$ifNull": [
"$shipping",
null
]
},
"_id": 0
}
}
]
$switch
- It will return documents/rows, if "price equals 50000 = equals" else if "price grater then 50000 = grater than" else if "price less than 50000 = less than"
URL
Request Payload[
{
"$project": {
"id": 1,
"price": 1,
"priceSummary": {
"$switch": {
"branches": [
{
"case": {
"$eq": [
"$price",
50000
]
},
"then": "equals"
},
{
"case": {
"$gt": [
"$price",
50000
]
},
"then": "greater than"
},
{
"case": {
"$lt": [
"$price",
50000
]
},
"then": "less than"
}
]
}
}
}
}
]
$concat
- It will return documents/rows, with concat "name" + "_" + "description" = name_Description.
URL
Request Payload[
{
"$project": {
"id": 1,
"name_Description": {
"$concat": [
"$name",
"_",
"$description"
]
}
}
}
]
$max
- It will return documents/rows, with concat "name" + "_" + "description" = name_Description.
URL
Request PayloadSupported headers
Header | Description |
---|---|
x-am-response-case | It will change the response keys text as requested case. noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase |
x-am-response-object-type | To get flat response we use this request header. no_action | make_flat |
x-am-meta | To get the meta-data of requested API. false | true |
x-am-secret | Place secret id from API Maker. |
x-am-internationalization |
We can get backend error messages in any user language and directly show them to the user in UI, so the user can take appropriate actions.
Provide saved internationalization name in request header. |
x-am-run-in-sandbox | System will try to run requests in maximum provided sandbox, so if 1 provided every request will run in one sandbox, even if we have multiple sandbox with multiple API Maker instances. |
x-am-content-type-response | We can provide response type in request header. As provided header value we can expect the response type. application/json | text/xml | text/yaml |
x-am-cache-control | To reset the cache of the requested API manually and get fresh data, we can use 'x-am-cache-control' request header. no_action | reset_cache |
x-am-get-encrypted-data | Encrypt response data and get in to the response. no_encryption | get_only_encryption | get_data_and_encryption |
x-am-authorization | Provide token of API user in "x-am-authorization" header which will be generated from API Users inside API Maker. |
x-am-user-authorization | User token should be provided in 'x-am-user-authorization' header which will be generated based on some database user if required. |
x-aws-authorization | Provide AWS Cognito token in request header 'x-aws-authorization', if required. |
x-google-authorization | Provide Google user token in request header 'x-google-authorization', if required. |
x-azure-authorization | Provide Azure active directory token in request header 'x-azure-authorization', if required. |
x-no-compression | If user do not send 'x-no-compression' in request header, and response characters are more than value of "maxCharsResToCache" than the response will be compressed. |
x-am-sandbox-timeout | If any API did not give a response within given time, the sandbox will break and give a proper error message in the response. |
x-am-encrypted-payload | When user sent encrypted payload, user must have to sent "x-am-encrypted-payload:true". |