Links

Find

List records from specified collection
Finds database records. You can pass projection to return record fields you care about. Also, you can include referenced collections to have all that information in one place.
get
https://api.codemash.io/
/{version}/db/{CollectionName}/find
[Find] - List records from specified collection
post
https://api.codemash.io/
/{version}/db/{CollectionName}/find
[Find] - List records from specified collection

Finds database records. You can pass projection to return record fields you care about. Also, you can include referenced collections to have all that information in one place. https://docs.codemash.io/api/database/collections/find

Parameters
No parameters
Responses
cURL
Node.js
.NET
PHP
Untitled
  1. 1.
    Ensure that your Project Id and API Key are correct
  2. 2.
    Ensure that your Service user holds enough permissions to query database collection.
  3. 3.
    If you use more than one database, please provide ClusterId; otherwise, the default database will be used.
GET - Gets all records from Collection "Companies."
curl --location --request GET 'https://api.codemash.io/v2/db/companies/find' \
--header 'X-CM-ProjectId: 7254937f-ad77-4d00-9b35-c2af7841d21b' \
--header 'Authorization: Bearer ebis52*******yUfrX'
POST - Gets all records from Collection "Companies" where company code is equal to "123"
curl --location --request POST 'https://api.codemash.io/v2/db/companies/find' \
--header 'X-CM-ProjectId: 7254937f-ad77-4d00-9b35-c2af7841d21b' \
--header 'Authorization: Bearer ebis52*******yUfrX' \
--header 'Content-Type: application/json' \
--data-raw '{ "filter": "{ code: 123 }"}'
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;
}
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.
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.
Last modified 3mo ago