Find

Overview of collection find method

get
Find

https://api.codemash.io/:version/db/:collectionName/find
Gets many records by using a filter. This endpoint accepts GET and POST methods.
Request
Response
Request
Path Parameters
version
required
string
A version of the API endpoint.
collectionName
required
string
The name of the collection to get records from.
Headers
Authorization
required
string
Secret API key which belongs to your project or user. Not required if using cookies with a session ID.
x-cm-projectid
required
string
Your project's ID. Can be passed as a query parameter.
Query Parameters
filter
required
string
Filter document. This allows you to find records by a custom filter. More about filters follow the link below.
referencedFields
optional
array
Fields to left join. More about referencing fields follow the link below.
addReferencesFirst
optional
boolean
If set to true, left joins first before applying other processing to main records. More about referencing fields follow the link below.
cultureCode
optional
string
Language code. If your records have translatable fields, those fields will only include this specified language. If not provided, will take language from the Accept-Language header.
sort
optional
string
Sort document. This allows you to sort your records. More about sorting follow the link below.
projection
optional
string
Projection document. This allows you to specify what fields to return decreasing the amount of data transferred. More about projections follow the link below.
pageSize
optional
integer
Amount of records to return.
pageNumber
optional
integer
The page to return. More about paging follow the link below.
includeSchema
optional
boolean
If set to true, includes your collection details in the response.
includeUserNames
optional
boolean
If set to true will inject referenced user(s) information.
includeRoleNames
optional
boolean
If set to true will inject role(s) information.
includeCollectionNames
optional
boolean
If set to true will inject referenced collections.
includeTermNames
optional
boolean
If set to true will inject referenced terms.
excludeCulture
optional
boolean
Culture code or Accept-Language header will be used for translatable fields. If you want to get values in all languages, set this as true.
Response
200: OK
Returns a list of records. Here singular quotes are used to avoid escaping double quotes.
{
"result": "[{ '_id': '5e37136bf59f3a3f940b99a4', 'name': 'John' }]",
"totalCount": 1,
"schema": null,
}
.NET
Node
PHP
.NET
var client = new CodeMashClient(apiKey, projectId);
var service = new CodeMashRepository<Person>(client);
var persons = await service.FindAsync(
x => true,
new DatabaseFindOptions()
);

Check the docs about entities on how the response records are deserialized into your class objects.

Node
import { db } from 'codemash';
// gets all first 100 employees
export async function getEmployees() {
return await db.getRecords('emplpyees', 0, 100);
}
// gets all first 100 active employees
// get only first name and last name - projection
// sort out by created on date in DESC order.
export async function getActiveEmployees() {
const filter = JSON.stringify({ 'is_active': true });
const response =
await db.getRecords('employees', 0, 100,
{ first_name: 1, last_name: 1 },
filter,
{ created_on: -1 });
return response;
}
PHP
use Codemash\CodemashClient;
use Codemash\CodemashDb;
class CodemashService
{
protected CodemashDb $codemashDb;
protected string $collectionName = '{YOUR_COLLECTION_NAME}';
public function __construct()
{
$secretKey = '{YOUR_SECRET_KEY}';
$projectId = '{YOUR_PROJECT_ID}';
$client = new CodemashClient($secretKey, $projectId);
$this->codemashDb = new CodemashDb($client);
}
public function find()
{
$responseData = $this->codemashDb->findMany([
'collectionName' => 'employees',
'filter' => [
'address' => 'New York',
],
]);
}
}

Check the docs on how to form projections, filters, sorting, paging. Check the docs on how to use references.