Links

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.
get
https://api.codemash.io/
/{version}/db/{CollectionName}/count
[Count] - Get the amount of records in a collection.
post
https://api.codemash.io/
/{version}/db/{CollectionName}/count
[Count] - Get the amount of records in a collection.
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. 1.
    Create Employees collection and other related taxonomies from the template. See instructions here.​
  2. 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
.NET
Node.js
TypeScript
​
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'
​
​
​
IRepository<BusinessTrip> Trips { get; set; }
​
var amount = await Trips.CountAsync();
​
Console.WriteLine(amount); // 15
​
Please remember you need to initialize Repo first to avoid getting a NullReference exception. See how you can do that by following this link.
Coming Soon
Coming Soon
Let's filter some records by date ranges.
cURL
.NET
Node.js
TypeScript
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
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.
IRepository<BusinessTrip> Trips { get; set; }
​
var from = DateTime.Now.AddDays(+10).ToUnixTimeMs();
var tripsIn10Days = await Trips.CountAsync(x => x.From > from);
​
Console.WriteLine(tripsIn10Days); // 7
​
We can pass the date range as well to find out trips from the last 30 days
​
IRepository<BusinessTrip> Trips { get; set; }
​
var from = DateTime.Now.AddDays(-30).ToUnixTimeMs();
var to =DateTime.Now.ToUnixTimeMs();
​
var recentTrips = await Trips.CountAsync(x => x.From > from && x.To <= to);
​
Console.WriteLine(recentTrips); // 24
​
The filter can be:
  1. 1.
    Valid JSON (MQL - MongoDB query language)
  2. 2.
    Expression<Func<T,bool>>
  3. 3.
    FilterDefinition<T>
​
​See more examples of how you can leverage filters in .NET
​
​
​
​
And last one example. Let's find all employee business trips that are planned for the future.
cURL
.NET
Node.js
TypeScript
We assume that:
  1. 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. 2.
    We have an employee Id - employee
  3. 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 }}"}'
​
We assume that:
  1. 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. 2.
    We have an employee Id - employee
  3. 3.
    We have a date from, e.g., DateTime.Now converted to the Unix time in milliseconds
​
IRepository<BusinessTrip> Trips { get; set; }
​
var f = Builders<BusinessTrip>.Filter;
​
var from = f.Gte(x => x.From, from);
var inCountry = f.Eq(x => x.CountryId, country);
var withEmployee =
f.ElemMatch(x => x.Employees, x => x.EmployeeId == employee);
​
var tripsCount =
await Trips.CountAsync(from & inCountry & withEmployee);
So in the example above, we found the number of future trips of one particular employee to one country.
​
​
​

Visit our GitHub repo to see more examples:

Try out our API:

​