Find One
Overview of collection find one methods
get
https://api.codemash.io
/:version/db/:collectionName/:id
Find One (by ID)
.NET
Node
PHP
var client = new CodeMashClient(apiKey, projectId);
var service = new CodeMashRepository<Person>(client);
โ€‹
var person = await service.FindOneByIdAsync(
"{RECORD_ID}",
new DatabaseFindOneOptions()
);
Check the docs about entities on how the response record is deserialized into your class object.
import { db } from 'codemash';
โ€‹
export async function getEmployeeDetails(id) {
const response = await db.getRecord('employees', id);
return response;
}
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 findOneById()
{
$responseData = $this->codemashDb->get([
'collectionName' => 'employees',
'id' => '{EMPLOYEE_ID}',
]);
}
}
Check the docs on how to form projections. Check the docs on how to use references.
get
https://api.codemash.io
/:version/db/:collectionName/findOne
Find One (by using a filter)
.NET
Node
PHP
var client = new CodeMashClient(apiKey, projectId);
var service = new CodeMashRepository<Person>(client);
โ€‹
var person = await service.FindOneAsync(
x => x.Id == "{RECORD_ID}",
new DatabaseFindOneOptions()
);
Check the docs about entities on how the response record is deserialized into your class object.
import { db } from 'codemash';
โ€‹
export async function getEmployeeByUserId(id) {
const filter = { userId : id };
return await db.getRecordWithFilter(collectionName, filter, null);
}
โ€‹
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 findOneByFilter()
{
$responseData = $this->codemashDb->findOne([
'collectionName' => 'employees',
'filter' => [
'address' => 'Los Angeles',
],
]);
}
}
Check the docs on how to form projections, filters. Check the docs on how to use references.
Last modified 1yr ago
Copy link
On this page
get
Find One (by ID)
get
Find One (by using a filter)