Find One
Gets record by specified database unique id or filter.
Finds one database record. 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}/{Id}
[FindOne] - Gets record by specified database unique id.
post
https://api.codemash.io/
/{version}/db/{CollectionName}/{Id}
[FindOne] - Gets record by specified database unique id.
Finds one database record. 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-one
Parameters
No parameters
Responses
.NET
Node
PHP
var client = new CodeMashClient(apiKey, projectId);
var service = new CodeMashRepository<Person>(client);
var person = await service.FindOneByIdAsync(
"{RECORD_ID}",
new DatabaseFindOneOptions()
);
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}',
]);
}
}
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()
);
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',
],
]);
}
}
Last modified 9mo ago