Count

Get the amount of records in a collection.

When you want to display how many records your collection has without displaying them. You can pass filter and paging parameters to filter records upfront and get the amount of filtered records.

You register employees from when to when s/he wants to travel, in which country, and you can attach documents related to the business trip. You can use our templates or create collections and taxonomies manually by following our instructions.

Prerequisites:

  1. Create Employees collection and other related taxonomies from the template. See instructions here.

  2. Create a collection of "Business Trips." You can do it manually or just copy-paste JSON and UI schemas into CodeMash Dashboard. See instructions here. The schema itself can be found here.

Let's say you have some records inserted in the "Business Trips" collection.

Let's get all the amount of records in the collection.

curl -X 'GET' \
  'https://api.codemash.io/v2/db/business-trips/count' \
  -H 'Authorization: Bearer ***' \
  -H 'X-CM-ProjectId: e1aa5e3b-f16d-4f43-a315-2d89f7633dc3' \
  -H 'Accept: application/json'

Let's filter some records by date ranges.

Let's find business trips that will start in 10 days. We store the "From" data field in CodeMash as a date field, which converts at the end as a UNIX timestamp. See more about the Date field.

#!/bin/bash

FROM=`date -d "+10 days" +%s`

curl -X 'POST' \
  'https://api.codemash.io/v2/db/business-trips/count' \
  -H 'Authorization: Bearer ***' \
  -H 'X-CM-ProjectId: e1aa5e3b-f16d-4f43-a315-2d89f7633dc3' \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{ "filter": "{ from : { $gte : '$FROM'  }}" }'

We can pass the date range as well to find out trips from the last 30 days.

#!/bin/bash

FROM=`date -d "-30 days" +%s`
TO=`date +%s`

curl -X 'POST' \
  'https://api.codemash.io/v2/db/business-trips/count' \
  -H 'Authorization: Bearer ***' \
  -H 'X-CM-ProjectId: e1aa5e3b-f16d-4f43-a315-2d89f7633dc3' \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{ "filter": "{ from : { $gt : '$FROM' }, to: { $lt: '$TO' }}"  }'

See more examples of how you can leverage filters

And last one example. Let's find all employee business trips that are planned for the future.

We assume that:

  1. We have a country we are interested in - taxonomy term Id. E.g., We can fetch all terms from the taxonomy called countries and find the term Id of France.

  2. We have an employee Id - employee

  3. We have a date from, the Unix time

curl -X 'POST' \
  'https://api.codemash.io/v2/db/business-trips/count' \
  -H 'Authorization: Bearer ***' \
  -H 'X-CM-ProjectId: e1aa5e3b-f16d-4f43-a315-2d89f7633dc3' \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{ "filter": "{ from : { $gte : 1730969827000  }}"}'

Visit our GitHub repo to see more examples:

Try out our API:

Last updated