Find

Overview of collection find method

get
Find

https://api.codemash.io/:version/db/:collectionName/find
Gets many records by filter. This endpoint accepts GET and POST methods.
Request
Response
Request
Path Parameters
version
required
string
A version of API endpoint.
collectionName
required
string
The name of 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 session ID.
x-cm-projectid
required
string
Your project's ID. Can be passed as query parameter.
Query Parameters
filter
required
string
Filter document. This allows you to find records by 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 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 response.
includeUserNames
optional
boolean
If set to true, will inject your user references.
includeRoleNames
optional
boolean
If set to true, will inject your role references.
includeCollectionNames
optional
boolean
If set to true, will inject your referenced collections.
includeTermNames
optional
boolean
If set to true, will inject your 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
.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;
}

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